package com.jwsoft.manager.core.integration.bigScreen.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bifang.assistant.common.vo.BaseVO;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.engine.assistant.core.annotation.OpApi;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.enums.FuncTypeEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.engine.cache.redis.RedisHelper;
import com.bifang.engine.data.core.util.PagerUtil;
import com.bifang.module.base.common.vo.common.CommonVO;
import com.bifang.module.base.common.vo.dict.DictQueryVO;
import com.bifang.module.base.core.integration.CommonIntegration;
import com.bifang.module.base.core.integration.DictIntegration;
import com.bifang.module.system.core.dao.service.SysDictService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.vo.bigScreen.analysisXq.*;
import com.jwsoft.manager.common.vo.eduAddress.EduAddressVO;
import com.jwsoft.manager.common.vo.eduAddress.SchoolAddressQueryVO;
import com.jwsoft.manager.common.vo.eduAddressTree.AddressAndSchoolVO;
import com.jwsoft.manager.common.vo.eduAddressTree.AddressReqVO;
import com.jwsoft.manager.common.vo.eduSchool.EduSchoolVO;
import com.jwsoft.manager.common.vo.eduSchoolHx.EduSchoolHxKeyVO;
import com.jwsoft.manager.core.dao.mapper.*;
import com.jwsoft.manager.core.dao.model.*;
import com.jwsoft.manager.core.dao.service.*;
import com.jwsoft.manager.core.integration.bigScreen.AnalysisXqIntegration;
import com.jwsoft.manager.core.integration.eduAddressTree.impl.EduAddressTreeIntegrationImpl;
import com.jwsoft.manager.core.util.EduHelper;
import jodd.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

import static org.springframework.beans.BeanUtils.copyProperties;

@ApiService(funcCode = "AnalysisXq", title = "大屏接口")
public class AnalysisXqIntegrationImpl implements AnalysisXqIntegration {
    @Autowired
    EduSchoolService eduSchoolService;
    @Autowired
    EduBigscreenZbtj02Service eduBigscreenZbtj02Service;
    @Autowired
    EduBigscreenZbtj01Service eduBigscreenZbtj01Service;
    @Autowired
    EduSchoolRsService eduSchoolRsService;
    @Autowired
    EduStudentTjService eduStudentTjService;
    @Autowired
    EduSchoolXwtjService eduSchoolXwtjService;
    @Autowired
    EduSchoolHxService eduSchoolHxService;
    @Autowired
    EduEnrolYbmService eduEnrolYbmService;
    @Autowired
    EduEnrolYbmCalculateService eduEnrolYbmCalculateService;
    @Autowired
    EduStudentEnrollCalculateService eduStudentEnrollCalculateService;

    @Autowired
    EduAddressTreeIntegrationImpl eduAddressTreeIntegrationImpl;

    @Autowired
    EduHelper eduHelper;
    @Autowired
    private RedisHelper redisHelper;
    private final String getEnrolYbm = "task:getEnrolYbm";
    @Autowired
    EduSocialSecurityService eduSocialSecurityService;
    @Autowired
    EduLivePlaceService eduLivePlaceService;
    @Autowired
    EduCompanyService eduCompanyService;
    @Autowired
    EduNetsignService eduNetsignService;
    @Autowired
    EduAnalyHjService eduAnalyHjService;

    @Autowired
    EduHouseDetailService eduHouseDetailService;
    @Autowired
    EduHouseService eduHouseService;
    @Autowired
    EduAddressHistoryService eduAddressHistoryService;

    @Autowired
    EduHouseholdService eduHouseholdService;

    @Autowired
    EduEnrollmenBrochureService eduEnrollmenBrochureService;
    @Autowired
    EduAddressService eduAddressService;
    @Autowired
    EduAddressSchoolService eduAddressSchoolService;
    @Autowired
    EduSchoolConfigService eduSchoolConfigService;
    @Autowired
    EduSchoolPlanService eduSchoolPlanService;
    @Autowired
    EduStudentEnrollPreService eduStudentEnrollPreService;
    @Autowired
    EduBigscreenFiveyearGtService eduBigscreenFiveyearGtService;
    @Autowired
    EduStudentEnrollService eduStudentEnrollService;
    @Autowired
    CommonIntegration commonIntegration;

    @Autowired
    EduStudentEnrollBeforeService  eduStudentEnrollBeforeService;
    @Autowired
    SysDictService sysDictService;
    @Autowired
    EduAreaService eduAreaService;
    @Autowired
    DictIntegration dictIntegration;
    @Autowired
    EduEnrolYbmCalculateMapper ybmCalculateMapper;
    @Autowired
    EduEnrolYbmMapper ybmMapper;
    @Autowired
    EduBigscreenFiveyearGtMapper fyMapper;

    @Autowired
    EduBigscreenZbtj02Mapper bigscreen02Mapper;
    @Autowired
    EduBigscreenZbtj01Mapper bigscreen01Mapper;

    @Autowired
    EduAnalyHjMapper eduAnalyHjMapper;


    @Override
    @OpApi(funcCode = "EduAnalysisXq0001", title = "总览学校信息", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public SchoolOverviewXqVO getSchoolOverview(SchoolOverviewXqQueryVO vo) {
        AtomicReference<GetDictVO> gdvo = new AtomicReference<>(new GetDictVO());
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }

        SchoolOverviewXqVO soVO = new SchoolOverviewXqVO();
        soVO.setYear(vo.getYear());
        soVO.setAreaCode(vo.getAreaCode());

        gdvo.get().setDictField("AREA");
        gdvo.get().setDictKey(vo.getAreaCode());
        gdvo.get().setAstype("1");
        soVO.setAreaCodeName(getDictName(gdvo.get()).getDictValue());

        //学校基础信息
        QueryWrapper<EduSchool> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("School_Nature","School_Category",
                        "School_Name",
                        "Street")
                .eq("Del",0)
                .in("school_category",2,3)
                .ne("street","Z2")
                .notIn("org_id","E3392DF5-109B-4E83-9E94-033AF27506E6","5D805C74-6D25-4ACC-ADE5-A5F538973769")
                .eq("Area_Code",vo.getAreaCode());
        if(!ObjectUtils.isEmpty(vo.getStreet())){
            queryWrapper.eq("Street",vo.getStreet());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            queryWrapper.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            queryWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        int zs = 0;
        int mb=0;
        int gb = 0;
        List<EduSchool> list = eduSchoolService.list(queryWrapper);
        for (EduSchool eduSchool : list) {
            zs = zs + 1;
            if ("1".equals(eduSchool.getSchoolNature())) {
                mb = mb + 1;
            }
            if ("0".equals(eduSchool.getSchoolNature())) {
                gb = gb + 1;
            }
        }
        soVO.setSchoolCount(zs);
        soVO.setSchoolMbCount(mb);
        soVO.setSchoolGbCount(gb);

        //计划招生人数 edu_school_config
        QueryWrapper<EduSchoolConfig> qwconfig = new QueryWrapper<>();
        qwconfig.select("sum(enrolment) as studentJhCount")
                .eq("Del",0)
                .in("school_category",2,3)
                .notIn("school_id","E3392DF5-109B-4E83-9E94-033AF27506E6","5D805C74-6D25-4ACC-ADE5-A5F538973769")
                .eq("year",vo.getYear())
                .eq("Area_Code",vo.getAreaCode());
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            qwconfig.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qwconfig.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String, Object> map = eduSchoolConfigService.getMap(qwconfig);
        if(!ObjectUtils.isEmpty(map)){
            BigDecimal sumCount = (BigDecimal) map.get("studentJhCount");
            soVO.setStudentJhCount(sumCount.intValue());
        }else{
            QueryWrapper<EduSchoolConfig> qwconfig1 = new QueryWrapper<>();
            qwconfig1.select("sum(enrolment) as studentJhCount")
                    .eq("Del",0)
                    .in("school_category",2,3)
                    .notIn("school_id","E3392DF5-109B-4E83-9E94-033AF27506E6","5D805C74-6D25-4ACC-ADE5-A5F538973769")
                    .eq("year",vo.getYear()-1)
                    .eq("Area_Code",vo.getAreaCode());
            if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
                qwconfig1.eq("School_Nature",vo.getSchoolNature());
            }
            if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
                qwconfig1.eq("School_Category",vo.getSchoolCategory());
            }
            Map<String, Object> map1 = eduSchoolConfigService.getMap(qwconfig1);
            if(!ObjectUtils.isEmpty(map1)){
                BigDecimal sumCount = (BigDecimal) map1.get("studentJhCount");
                soVO.setStudentJhCount(sumCount.intValue());
            }else{
                soVO.setStudentJhCount(0);
            }
        }


        //当年适龄人数 EduStudentEnrollPre
        QueryWrapper<EduStudentEnrollPre> qwpre = new QueryWrapper<>();
        qwpre.select("count(*) cn")
                .eq("del",0)
                .in("school_category",2,3)
                .notIn("school_id","E3392DF5-109B-4E83-9E94-033AF27506E6","5D805C74-6D25-4ACC-ADE5-A5F538973769")
                .eq("year",vo.getYear());
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qwpre.eq("school_category",vo.getSchoolCategory());
        }
        Map<String, Object> mappre = eduStudentEnrollPreService.getMap(qwpre);
        if(!ObjectUtils.isEmpty(mappre)){
            int sumCount = Integer.parseInt(mappre.get("cn").toString());
            soVO.setStudentSlCount(sumCount);
        }else{
            soVO.setStudentSlCount(0);
        }
//        //查询上年学校数据，计算同比增长数
        LambdaQueryWrapper<EduBigscreenFiveyearGt> queryWrapper2 = new LambdaQueryWrapper<>();
        queryWrapper2.eq(EduBigscreenFiveyearGt::getDel,0);
        queryWrapper2.eq(EduBigscreenFiveyearGt::getYear,vo.getYear()-1);
        queryWrapper2.eq(EduBigscreenFiveyearGt::getAreaCode,vo.getAreaCode());
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            queryWrapper2.eq(EduBigscreenFiveyearGt::getSchoolCategory,vo.getSchoolCategory());
        }
        soVO.setSchoolIncreaseCount(zs -(int) eduBigscreenFiveyearGtService.count(queryWrapper2));
        //------------------------------------------------------------------------------//
        //5年增长趋势
        EchartsInfoVO eivo = new EchartsInfoVO();
        QueryWrapper<EduBigscreenFiveyearGt> qwgt = new QueryWrapper<>();
        qwgt.select("sum(act_num) as act_num,sum(pla_num) as pla_num,year")
                .eq("Del",0)
                .in("school_category",2,3)
                .notIn("school_id","E3392DF5-109B-4E83-9E94-033AF27506E6","5D805C74-6D25-4ACC-ADE5-A5F538973769")
                .le("year",vo.getYear())
                .ge("year",vo.getYear()-5)
                .groupBy("year")
                .orderByAsc("year");
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qwgt.eq("school_category",vo.getSchoolCategory());
        }

        List<EduBigscreenFiveyearGt> biglist= eduBigscreenFiveyearGtService.list(qwgt);

        EchartsDataVO edvo_rs = new EchartsDataVO();
        EchartsDataVO edvo_xw = new EchartsDataVO();
        edvo_rs.setName("人数");
        edvo_rs.setTitle("人数");
        edvo_xw.setName("学位");
        edvo_xw.setTitle("学位");

        Map<Integer,GetFiveYearVO> mapObj_rs = new HashMap<>();
        Map<Integer,GetFiveYearVO> mapObj_xw = new HashMap<>();
        for(EduBigscreenFiveyearGt edvo : biglist){
            GetFiveYearVO gv_rs = new GetFiveYearVO();
            gv_rs.setName(edvo.getYear()+"");
            gv_rs.setValue(edvo.getActNum());
            mapObj_rs.put(edvo.getYear(),gv_rs);
            GetFiveYearVO gv_xw = new GetFiveYearVO();
            gv_xw.setName(edvo.getYear()+"");
            gv_xw.setValue(edvo.getPlaNum());
            mapObj_xw.put(edvo.getYear(),gv_xw);
        }
        List<GetFiveYearVO> li3_rs = new ArrayList<>(mapObj_rs.values());
        edvo_rs.setData(li3_rs);
        List<GetFiveYearVO> li3_xw = new ArrayList<>(mapObj_xw.values());
        edvo_xw.setData(li3_xw);
        List<EchartsDataVO> li2 = new ArrayList<>();
        li2.add(0,edvo_rs);
        li2.add(1,edvo_xw);
        eivo.setList(li2);

        soVO.setZzqs(eivo);

        List<AreaXwpmVO> liax =getAreaXwpmVO(vo);
        liax.forEach(item -> {
            gdvo.set(new GetDictVO());
            gdvo.get().setDictField(item.getStreet());
            gdvo.get().setAstype("2");
            item.setStreetName(getDictName(gdvo.get()).getDictValue());
            gdvo.set(new GetDictVO());
            gdvo.get().setDictField("AREA");
            gdvo.get().setDictKey(vo.getAreaCode());
            gdvo.get().setAstype("1");
            item.setAreaCodeName(getDictName(gdvo.get()).getDictValue());
            item.setYear(vo.getYear());
            item.setAreaCode(vo.getAreaCode());
        });
        //区域学区排名
        soVO.setAreaXqpm(liax);
        return soVO;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0002", title = "总览地址信息", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public AddressOverviewXqVO getAddressOverview(AddressOverviewXqQueryVO vo) {
        GetDictVO gdvo =  new GetDictVO();
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }

        AddressOverviewXqVO AoVO = new AddressOverviewXqVO();
        AoVO.setAreaCode(vo.getAreaCode());
        gdvo.setDictField("AREA");
        gdvo.setDictKey(vo.getAreaCode());
        gdvo.setAstype("1");
        AoVO.setAreaCodeName(getDictName(gdvo).getDictValue());
        AoVO.setYear(vo.getYear());

        QueryWrapper<EduAddress> qwaddress = new QueryWrapper<>();
        qwaddress.select("ifnull(matching_status,'0') matching_status")
                .eq("Del",0);

        List<EduAddress> list = eduAddressService.list(qwaddress);
        if(!CollectionUtils.isEmpty(list)){
            Map<String,Long>map1 =  list.stream().collect(Collectors.groupingBy(EduAddress::getMatchingStatus,Collectors.counting()));
            if(!ObjectUtils.isEmpty(map1.get("1"))){
                AoVO.setAddressFpCount(map1.get("1").intValue());
            }else {
                AoVO.setAddressFpCount(0);
            }
            if(!ObjectUtils.isEmpty(map1.get("0"))){
                AoVO.setAddressWfpCount(map1.get("0").intValue());
            }else {
                AoVO.setAddressWfpCount(0);
            }

        }else{
            throw new AppException("未查询到相应数据");
        }

        AoVO.setAddressCount(list.size());
        //学校同比增长数
        QueryWrapper<EduAddressHistory> qwpeas = new QueryWrapper<>();
        qwpeas.select("count(*) cn")
                .eq("del",0)
                .notInSql("address_id","select address_id from edu_address_school where school_id in(select org_id from edu_school where school_category=1)")
                .eq("year",vo.getYear()-1);
        Map<String, Object> mappre = eduAddressHistoryService.getMap(qwpeas);
        if(!ObjectUtils.isEmpty(mappre)){
            int sumCount = Integer.parseInt(mappre.get("cn").toString());
            AoVO.setAddressIncreaseCount(list.size()- sumCount);
        }else{
            AoVO.setAddressIncreaseCount(0);
        }
        //异常地址情况
        //5年内增长趋势
        EchartsInfoVO eivo = new EchartsInfoVO();
        QueryWrapper<EduAddressSchool> qwgt = new QueryWrapper<>();
        qwgt.select("count(1) audit_id,DATE_FORMAT(create_time, \"%Y\") tree_id")
                .eq("Del",0)
                .in("school_category",2,3)
                .le("DATE_FORMAT(create_time, \"%Y\")",vo.getYear())
                .ge("DATE_FORMAT(create_time, \"%Y\")",vo.getYear()-5)
                .groupBy("DATE_FORMAT(create_time, \"%Y\")")
                .orderByAsc("DATE_FORMAT(create_time, \"%Y\")");

        List<EduAddressSchool> biglist= eduAddressSchoolService.list(qwgt);

        EchartsDataVO edvo_rs = new EchartsDataVO();
        edvo_rs.setName("地址数");
        edvo_rs.setTitle("地址数");

        Map<Integer,GetFiveYearVO> mapObj_rs = new HashMap<>();
        for(EduAddressSchool edvo : biglist){
            GetFiveYearVO gv_rs = new GetFiveYearVO();
            gv_rs.setName(edvo.getTreeId()+"");
            gv_rs.setValue(edvo.getAuditId().intValue());
            mapObj_rs.put(edvo.getTreeId().intValue(),gv_rs);
        }
        List<GetFiveYearVO> li3_rs = new ArrayList<>(mapObj_rs.values());
        edvo_rs.setData(li3_rs);
        List<EchartsDataVO> li2 = new ArrayList<>();
        li2.add(0,edvo_rs);
        eivo.setList(li2);

        AoVO.setZzqs(eivo);

        //地址来源
        AddressSourceVO asvo = new AddressSourceVO();
        QueryWrapper<EduAddress> qw_address = new QueryWrapper<>();
        qw_address.select("count(1) as cn")
                .eq("Del",0);
        Map<String,Object>map_address = eduAddressService.getMap(qw_address);
        if(!ObjectUtils.isEmpty(map_address)){
            int cn = Integer.parseInt(map_address.get("cn").toString());
            asvo.setAddressCount(cn);
        }

        QueryWrapper<EduHousehold> qw_ehh = new QueryWrapper<>();
        qw_ehh.select("count(distinct address_id) as cn")
                .eq("Del",0)
                .isNotNull("address_id");
        Map<String,Object>map_ehh = eduHouseholdService.getMap(qw_ehh);
        if(!ObjectUtils.isEmpty(map_ehh)){
            int cn = Integer.parseInt(map_ehh.get("cn").toString());
            asvo.setHouseHold(cn);
        }
        QueryWrapper<EduHouse> qw_eh = new QueryWrapper<>();
        qw_eh.select("count(distinct address_id) as cn")
                .eq("Del",0)
                .isNotNull("address_id");
        Map<String,Object>map_eh = eduHouseService.getMap(qw_eh);
        if(!ObjectUtils.isEmpty(map_eh)){
            int cn = Integer.parseInt(map_eh.get("cn").toString());
            asvo.setHouse(cn);
        }
        asvo.setOthers(AoVO.getAddressCount()-asvo.getHouse()-asvo.getHouseHold());
        AoVO.setAddressSource(asvo);
        //学校地址数排名
        List<SchoolAddressCountVO> resultList =  getSchoolAddressCountVO(vo);
        if(!CollectionUtils.isEmpty(resultList)){
            resultList = Convert.toList(SchoolAddressCountVO.class, resultList.subList(0,10));
        }

        AoVO.setSchoolAddressCountList(resultList);
        return AoVO;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0003", title = "学校学区地图信息", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public PageInfo<SchoolXqVO> getSchoolXqList(SchoolXqQueryVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        if (vo.getPageNum() == null || vo.getPageSize() == null || vo.getPageSize() == 0) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(10);
        }else{
            vo.setPageNum(vo.getPageNum()+1);
        }
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<SchoolXqVO> list = getSchoolXqVOList(vo);
        if(CollectionUtils.isEmpty(list)){
            vo.setYear(vo.getYear()-1);
            list = getSchoolXqVOList(vo);
            if(CollectionUtils.isEmpty(list)){
                return  null;
            }
        }
        PageInfo<SchoolXqVO> pageInfo = new PageInfo<>(list);
        list.forEach(item->{
            if(!ObjectUtils.isEmpty(item.getMapRegion())){
                item.setAsMapRegion(getArr(item.getMapRegion()));
            }
            GetDictVO gdvo = new GetDictVO();
            gdvo.setDictField("AREA");
            gdvo.setDictKey(vo.getAreaCode());
            gdvo.setAstype("1");
            item.setAreaCodeName(getDictName(gdvo).getDictValue());

            gdvo = new GetDictVO();
            gdvo.setDictField("SCHOOLNATURE");
            gdvo.setDictKey(item.getSchoolNature());
            gdvo.setAstype("1");
            item.setSchoolNatureName(getDictName(gdvo).getDictValue());

            gdvo = new GetDictVO();
            gdvo.setDictField("SCHOOLCATEGORY");
            gdvo.setDictKey(item.getSchoolCategory());
            gdvo.setAstype("1");
            item.setSchoolCategoryName(getDictName(gdvo).getDictValue());

            gdvo = new GetDictVO();
            gdvo.setDictField(item.getStreet());
            gdvo.setAstype("2");
            item.setStreetName(getDictName(gdvo).getDictValue());

        });

        return pageInfo;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0004", title = "单个学校详细信息", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public SchoolXqVO getSchoolInfo(SchoolXqQueryVO vo) {

        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getSchoolId())){
            throw new AppException("学校id不能为空");
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        SchoolXqVO sVO = getSchoolXqVO(vo);
        if(ObjectUtils.isEmpty(sVO)){
            return sVO;
        }
        GetDictVO gdvo = new GetDictVO();
        gdvo.setDictField("AREA");
        gdvo.setDictKey(vo.getAreaCode());
        gdvo.setAstype("1");
        sVO.setAreaCodeName(getDictName(gdvo).getDictValue());
        if(!ObjectUtils.isEmpty(sVO.getMapRegion())){
            sVO.setAsMapRegion(getArr(sVO.getMapRegion()));
        }

        if(!ObjectUtils.isEmpty(sVO.getMblLq()) && sVO.getMblLq()>0){
            double mbl = sVO.getMblLq().doubleValue()/sVO.getMblJh().doubleValue();
            String after = String.format("%.4f",mbl);
            double after_d = Double.parseDouble(after);
            sVO.setMbl(after_d);
        }

        if(!ObjectUtils.isEmpty(sVO.getStudentJhCountsn()) &&  sVO.getStudentJhCountsn()>0){
            double asavg = sVO.getStudentJhCount().doubleValue()/sVO.getStudentJhCountsn().doubleValue();
            String after = String.format("%.4f",asavg);
            double after_d = Double.parseDouble(after);
            sVO.setStudentIncreaseCount(after_d);
        }

        gdvo = new GetDictVO();
        gdvo.setDictField(sVO.getStreet());
        gdvo.setAstype("2");
        sVO.setStreetName(getDictName(gdvo).getDictValue());

        gdvo = new GetDictVO();
        gdvo.setDictField("SCHOOLNATURE");
        gdvo.setDictKey(sVO.getSchoolNature());
        gdvo.setAstype("1");
        sVO.setSchoolNatureName(getDictName(gdvo).getDictValue());

        gdvo = new GetDictVO();
        gdvo.setDictField("SCHOOLCATEGORY");
        gdvo.setDictKey(sVO.getSchoolCategory());
        gdvo.setAstype("1");
        sVO.setSchoolCategoryName(getDictName(gdvo).getDictValue());

        //查询年度各类别报名录取情况 List<SchoolBmLqVO>  bmlq

        //报名人数
        QueryWrapper<EduStudentEnroll> qwbm = new QueryWrapper<>();
        qwbm.select("count(*) as year,case when config_name ='A' then 'A' when config_name ='B' then 'B' when config_name ='C' then 'C' else '其他' end as config_name")
                .eq("Del",0)
                .eq("year",vo.getYear())
                .eq("school_id",vo.getSchoolId())
                .groupBy("case when config_name ='A' then 'A' when config_name ='B' then 'B' when config_name ='C' then 'C' else '其他' end");
        List<EduStudentEnroll> bmlist= eduStudentEnrollService.list(qwbm);

        //录取人数
        QueryWrapper<EduStudentEnroll> qwlq = new QueryWrapper<>();
        qwlq.select("count(*) as year,case when config_name ='A' then 'A' when config_name ='B' then 'B' when config_name ='C' then 'C' else '其他' end as config_name")
                .eq("Del",0)
                .eq("year",vo.getYear())
                .eq("school_id",vo.getSchoolId())
                .eq("enroll_status","2")
                .groupBy("case when config_name ='A' then 'A' when config_name ='B' then 'B' when config_name ='C' then 'C' else '其他' end");
        List<EduStudentEnroll> lqlist= eduStudentEnrollService.list(qwlq);

        //比对人数
        QueryWrapper<EduStudentEnrollBefore> qwbd = new QueryWrapper<>();
        qwbd.select("count(*) as year,case when config_name ='A' then 'A' when config_name ='B' then 'B' when config_name ='C' then 'C' else '其他' end as config_name")
                .eq("Del",0)
                .eq("year",vo.getYear())
                .eq("school_id",vo.getSchoolId())
                .groupBy("case when config_name ='A' then 'A' when config_name ='B' then 'B' when config_name ='C' then 'C' else '其他' end");
        List<EduStudentEnrollBefore> bdlist= eduStudentEnrollBeforeService.list(qwbd);

        //意向人数
        QueryWrapper<EduStudentEnrollBefore> qwyx = new QueryWrapper<>();
        qwyx.select("count(*) as year,case when config_name ='A' then 'A' when config_name ='B' then 'B' when config_name ='C' then 'C' else '其他' end as config_name")
                .eq("Del",0)
                .eq("year",vo.getYear())
                .eq("school_id",vo.getSchoolId())
                .inSql("student_enroll_pre_id", "select student_enroll_pre_id from edu_student_enroll_pre where del='0' and auth_status='1' and year='"+vo.getYear()+"' and school_id='"+vo.getSchoolId()+"'")
                .groupBy("case when config_name ='A' then 'A' when config_name ='B' then 'B' when config_name ='C' then 'C' else '其他' end");
        List<EduStudentEnrollBefore> yxlist= eduStudentEnrollBeforeService.list(qwyx);

        List<SchoolBmLqVO> sbmlqlistList = new ArrayList<>();
        for(EduStudentEnroll bmvo : bmlist){
            SchoolBmLqVO sbvo = new SchoolBmLqVO();
            sbvo.setStreet(sVO.getStreet());

            sbvo.setStreetName(sVO.getStreetName());
            sbvo.setSchoolNum(sVO.getSchoolNum());
            sbvo.setOrgId(sVO.getOrgId());
            sbvo.setAreaCode(sVO.getAreaCode());
            sbvo.setSchoolCategory(sVO.getSchoolCategory());
            sbvo.setYear(sVO.getYear());
            sbvo.setSchoolNature(sVO.getSchoolNature());
            sbvo.setSchoolName(sVO.getSchoolName());
            sbvo.setShortName(sVO.getShortName());
            sbvo.setSchoolNatureName(sVO.getSchoolNatureName());
            sbvo.setSchoolCategoryName(sVO.getSchoolCategoryName());
            sbvo.setConfigName(bmvo.getConfigName());
            sbvo.setBmCount(bmvo.getYear());
            //筛选list中不同类型的数据进行统计
            List<EduStudentEnroll> lqvo = lqlist.stream().filter(
                    item ->
                            item.getConfigName().equals(bmvo.getConfigName())
            ).collect(Collectors.toList());
            if(lqvo.size()==1){
                sbvo.setLqCount(lqvo.get(0).getYear());
            }

            List<EduStudentEnrollBefore> bdvolist = bdlist.stream().filter(
                    item ->
                            item.getConfigName().equals(bmvo.getConfigName())
            ).collect(Collectors.toList());
            if(bdvolist.size()==1){
                sbvo.setBdCount(bdvolist.get(0).getYear());
            }

            List<EduStudentEnrollBefore> yxvo = yxlist.stream().filter(
                    item ->
                            item.getConfigName().equals(bmvo.getConfigName())
            ).collect(Collectors.toList());
            if(yxvo.size()==1){
                sbvo.setYxCount(yxvo.get(0).getYear());
            }


            sbmlqlistList.add(sbvo);
        }
        sVO.setBmlq(sbmlqlistList);
        sVO.setStudentIncreaseCount((double) (sVO.getStudentJhCount()-sVO.getStudentJhCountsn()));
        //近5年各类别录取人数

        //近5年学校报名录取增长趋势
        EchartsInfoVO eivo = new EchartsInfoVO();
        QueryWrapper<EduBigscreenFiveyearGt> qwgt = new QueryWrapper<>();
        qwgt.select("sum(act_num) as act_num,sum(pla_num) as pla_num,year")
                .eq("Del",0)
                .in("school_category",2,3)
                .eq("school_id",vo.getSchoolId())
                .le("year",vo.getYear()-1)
                .ge("year",vo.getYear()-6)
                .groupBy("year")
                .orderByAsc("year");
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qwgt.eq("school_category",vo.getSchoolCategory());
        }

        List<EduBigscreenFiveyearGt> biglist= eduBigscreenFiveyearGtService.list(qwgt);

        EchartsDataVO edvo_rs = new EchartsDataVO();
        EchartsDataVO edvo_xw = new EchartsDataVO();
        edvo_rs.setName("人数");
        edvo_rs.setTitle("人数");
        edvo_xw.setName("学位");
        edvo_xw.setTitle("学位");

        Map<Integer,GetFiveYearVO> mapObj_rs = new HashMap<>();
        Map<Integer,GetFiveYearVO> mapObj_xw = new HashMap<>();
        for(EduBigscreenFiveyearGt edvo : biglist){
            GetFiveYearVO gv_rs = new GetFiveYearVO();
            gv_rs.setName(edvo.getYear()+"");
            gv_rs.setValue(edvo.getActNum());
            mapObj_rs.put(edvo.getYear(),gv_rs);
            GetFiveYearVO gv_xw = new GetFiveYearVO();
            gv_xw.setName(edvo.getYear()+"");
            gv_xw.setValue(edvo.getPlaNum());
            mapObj_xw.put(edvo.getYear(),gv_xw);
        }
        List<GetFiveYearVO> li3_rs = new ArrayList<>(mapObj_rs.values());
        edvo_rs.setData(li3_rs);
        List<GetFiveYearVO> li3_xw = new ArrayList<>(mapObj_xw.values());
        edvo_xw.setData(li3_xw);
        List<EchartsDataVO> li2 = new ArrayList<>();
        li2.add(0,edvo_rs);
        li2.add(1,edvo_xw);
        eivo.setList(li2);

        sVO.setZzqs(eivo);
        return sVO;

    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0005", title = "学校学位排名分页查询", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public List<SchoolXwpmVO> getSchoolXwpm(SchoolXwpmQueryVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        List<SchoolXwpmVO> resultList = new ArrayList<>();

        List<SchoolXwpmVO> liax =getSchoolXwpmVO(vo);
        if(!CollectionUtils.isEmpty(liax)){
            if(liax.get(0).getStudentJhCount()==0){
                SchoolXwpmQueryVO vo2 = new SchoolXwpmQueryVO();
                    copyProperties(vo,vo2);
                    vo2.setYear(vo.getYear()-1);
                liax =getSchoolXwpmVO(vo2);
            }
            int a  = liax.size();
            if(liax.size()>=5){
                a = 5;
            }
            resultList = Convert.toList(SchoolXwpmVO.class, liax.subList(0,a));
            resultList.forEach(item->{
                GetDictVO gdvo = new GetDictVO();
                gdvo.setDictField(item.getStreet());
                gdvo.setAstype("2");
                item.setStreetName(getDictName(gdvo).getDictValue());
                gdvo = new GetDictVO();
                gdvo.setDictField("AREA");
                gdvo.setDictKey(vo.getAreaCode());
                gdvo.setAstype("1");
                item.setAreaCodeName(getDictName(gdvo).getDictValue());
                item.setYear(vo.getYear());
                item.setAreaCode(vo.getAreaCode());

                gdvo = new GetDictVO();
                gdvo.setDictField("SCHOOLNATURE");
                gdvo.setDictKey(item.getSchoolNature());
                gdvo.setAstype("1");
                item.setSchoolNatureName(getDictName(gdvo).getDictValue());

                gdvo = new GetDictVO();
                gdvo.setDictField("SCHOOLCATEGORY");
                gdvo.setDictKey(item.getSchoolCategory());
                gdvo.setAstype("1");
                item.setSchoolCategoryName(getDictName(gdvo).getDictValue());
//                if(item.getStudentJhCount()==0){
//                    SchoolXwpmQueryVO vo2 = new SchoolXwpmQueryVO();
//                    copyProperties(vo,vo2);
//                    vo2.setOrgId(item.getOrgId());
//                    vo2.setYear(vo.getYear()-1);
//                    List<SchoolXwpmVO> liax2 =getSchoolXwpmVO(vo2);
//                    if(!CollectionUtils.isEmpty(liax2)){
//                        item.setStudentJhCount(liax2.get(0).getStudentJhCount());
//                    }
//                }
            });
            Integer[] arr={1};
            resultList=resultList.stream().peek(e->e.setNum(arr[0]++)).collect(Collectors.toList());
        }
        return resultList;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0006", title = "区域学位排名分页查询", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public List<AreaXwpmVO> getAreaXwpm(AreaXwpmQueryVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        SchoolOverviewXqQueryVO sxqvo = new SchoolOverviewXqQueryVO();
        copyProperties(vo,sxqvo);
        List<AreaXwpmVO> liax =getAreaXwpmVO(sxqvo);
        if(!CollectionUtils.isEmpty(liax)){
            if(liax.get(0).getStudentJhCount()==0){
                SchoolOverviewXqQueryVO vo2 = new SchoolOverviewXqQueryVO();
                copyProperties(vo,vo2);
                vo2.setYear(vo.getYear()-1);
                liax =getAreaXwpmVO(vo2);
            }
            int a = liax.size();
            if(liax.size()>=5){
                a = 5;
            }
            liax = Convert.toList(AreaXwpmVO.class, liax.subList(0,a));
        }
        liax.forEach(item -> {
            GetDictVO gdvo = new GetDictVO();
            gdvo.setDictField(item.getStreet());
            gdvo.setAstype("2");
            item.setStreetName(getDictName(gdvo).getDictValue());
            gdvo = new GetDictVO();
            gdvo.setDictField("AREA");
            gdvo.setDictKey(vo.getAreaCode());
            gdvo.setAstype("1");
            item.setAreaCodeName(getDictName(gdvo).getDictValue());
            item.setYear(vo.getYear());
            item.setAreaCode(vo.getAreaCode());
//            if(item.getStudentJhCount()==0){
//                SchoolOverviewXqQueryVO vo2 = new SchoolOverviewXqQueryVO();
//                copyProperties(vo,vo2);
//                vo2.setStreet(item.getStreet());
//                vo2.setYear(vo.getYear()-1);
//                List<AreaXwpmVO> liax2 =getAreaXwpmVO(vo2);
//                if(!CollectionUtils.isEmpty(liax2)){
//                    item.setStudentSlCount(liax2.get(0).getStudentSlCount());
//                }
//            }
        });
        return liax;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0007", title = "总体人数查询", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public HouseHoldRsVO getHouseHoldRs(SchoolOverviewXqQueryVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }

        QueryWrapper<EduAnalyHj> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("hj_type");
        queryWrapper.eq("del",0);
        queryWrapper.eq("year",vo.getYear());
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            queryWrapper.eq("School_Category",vo.getSchoolCategory());
        }
        List<EduAnalyHj> listesep = eduAnalyHjService.list(queryWrapper);

        HouseHoldRsVO hhrsvo = new HouseHoldRsVO();
        if(!CollectionUtils.isEmpty(listesep)){
            Map<String,Long>map1 =  listesep.stream().collect(Collectors.groupingBy(EduAnalyHj::getHjType,Collectors.counting()));
            if(!ObjectUtils.isEmpty(map1.get("1"))){
                hhrsvo.setBdrs(map1.get("1").intValue());
            }
            if(!ObjectUtils.isEmpty(map1.get("0"))){
                hhrsvo.setWdrs(map1.get("0").intValue());
            }
        }

        //计划招生人数
        QueryWrapper<EduSchoolConfig> qwconfig = new QueryWrapper<>();
        qwconfig.select("sum(enrolment) as studentJhCount")
                .eq("Del",0)
                .in("school_category",2,3)
                .notIn("school_id","E3392DF5-109B-4E83-9E94-033AF27506E6","5D805C74-6D25-4ACC-ADE5-A5F538973769")
                .eq("year",vo.getYear())
                .eq("Area_Code",vo.getAreaCode());
        if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
            qwconfig.eq("School_Nature",vo.getSchoolNature());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qwconfig.eq("School_Category",vo.getSchoolCategory());
        }
        Map<String, Object> map = eduSchoolConfigService.getMap(qwconfig);
        if(!ObjectUtils.isEmpty(map)){
            BigDecimal sumCount = (BigDecimal) map.get("studentJhCount");
            hhrsvo.setJhcount(sumCount.intValue());
        }else{
            QueryWrapper<EduSchoolConfig> qwconfig1 = new QueryWrapper<>();
            qwconfig1.select("sum(enrolment) as studentJhCount")
                    .eq("Del",0)
                    .in("school_category",2,3)
                    .notIn("school_id","E3392DF5-109B-4E83-9E94-033AF27506E6","5D805C74-6D25-4ACC-ADE5-A5F538973769")
                    .eq("year",vo.getYear()-1)
                    .eq("Area_Code",vo.getAreaCode());
            if(!ObjectUtils.isEmpty(vo.getSchoolNature())){
                qwconfig1.eq("School_Nature",vo.getSchoolNature());
            }
            if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
                qwconfig1.eq("School_Category",vo.getSchoolCategory());
            }
            Map<String, Object> map1 = eduSchoolConfigService.getMap(qwconfig1);
            if(!ObjectUtils.isEmpty(map1)){
                BigDecimal sumCount = (BigDecimal) map1.get("studentJhCount");
                hhrsvo.setJhcount(sumCount.intValue());
            }else {
                hhrsvo.setJhcount(0);
            }

        }

        hhrsvo.setSlcount(listesep.size());

        return hhrsvo;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0008", title = "信息采集总览", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public AcquOverviewVO getAcquOverviewVO(HandConInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        AcquOverviewVO aovo = new AcquOverviewVO();

        QueryWrapper<EduStudentEnrollPre> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("ifnull(auth_status,'0') auth_status");
        queryWrapper.eq("del",0);
        queryWrapper.eq("year",vo.getYear());

        List<EduStudentEnrollPre> li_eseb = eduStudentEnrollPreService.list(queryWrapper);
        if(!CollectionUtils.isEmpty(li_eseb)){
            Map<String,Long>map1 =  li_eseb.stream().collect(Collectors.groupingBy(EduStudentEnrollPre::getAuthStatus,Collectors.counting()));
            aovo.setCollectYcj(li_eseb.size());
            if(!ObjectUtils.isEmpty(map1.get("1"))){
                aovo.setCollectYhs(map1.get("1").intValue());
            }else {
                aovo.setCollectYhs(0);
            }

        }else{
            throw new AppException("未查询到相应数据");
        }

        QueryWrapper<EduStudentEnrollPre> qw_pre = new QueryWrapper<>();
        qw_pre.select("ifnull(if(family_flag= 1, 1, 0),'0') family_flag");
        qw_pre.eq("del",0);
        qw_pre.eq("year",vo.getYear());

        List<EduStudentEnrollPre> li_pre = eduStudentEnrollPreService.list(qw_pre);
        if(!CollectionUtils.isEmpty(li_pre)){
            Map<String,Long>map1 =  li_pre.stream().collect(Collectors.groupingBy(EduStudentEnrollPre::getFamilyFlag,Collectors.counting()));
            if(!ObjectUtils.isEmpty(map1.get("1"))){
                aovo.setCollectYtg(map1.get("1").intValue());
            }else {
                aovo.setCollectYtg(0);
            }
            if(!ObjectUtils.isEmpty(map1.get("0"))){
                aovo.setCollectWtg(map1.get("0").intValue());
            }else {
                aovo.setCollectWtg(0);
            }
        }else{
            throw new AppException("未查询到相应数据");
        }
        return aovo;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0009", title = "核实协统数据使用情况", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public DyIndividuationVO getDyIndividuationVO(HandConInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        DyIndividuationVO divo = new DyIndividuationVO();
        //户籍
        QueryWrapper<EduHousehold> qw_hh = new QueryWrapper<>();
        qw_hh.select("count(1) cn");
        qw_hh.eq("del",0);
        qw_hh.eq("year",vo.getYear());
        qw_hh.eq("area_code",vo.getAreaCode());
        Map<String, Object> map_hh = eduHouseholdService.getMap(qw_hh);
        if(!ObjectUtils.isEmpty(map_hh)){
            int sumCount = Integer.parseInt(map_hh.get("cn").toString());
            divo.setHouseholdcn(sumCount);
        }else{
            divo.setHouseholdcn(0);
        }
        //房产
        QueryWrapper<EduHouse> qw_h = new QueryWrapper<>();
        qw_h.select("count(1) cn");
        qw_h.eq("del",0);
        qw_h.eq("year",vo.getYear());
        qw_h.eq("area_code",vo.getAreaCode());
        Map<String, Object> map_h = eduHouseService.getMap(qw_h);
        if(!ObjectUtils.isEmpty(map_h)){
            int sumCount = Integer.parseInt(map_h.get("cn").toString());
            divo.setHousecn(sumCount);
        }else{
            divo.setHousecn(0);
        }
        //网签
        QueryWrapper<EduNetsign> qw_n = new QueryWrapper<>();
        qw_n.select("count(1) cn");
        qw_n.eq("del",0);
        qw_n.eq("year",vo.getYear());
        qw_n.eq("area_code",vo.getAreaCode());
        Map<String, Object> map_n = eduNetsignService.getMap(qw_n);
        if(!ObjectUtils.isEmpty(map_n)){
            int sumCount = Integer.parseInt(map_n.get("cn").toString());
            divo.setNetsigncn(sumCount);
        }else{
            divo.setNetsigncn(0);
        }

        //企业
        QueryWrapper<EduCompany> qw_c = new QueryWrapper<>();
        qw_c.select("count(1) cn");
        qw_c.eq("del",0);
        qw_c.eq("year",vo.getYear());
        qw_c.eq("area_code",vo.getAreaCode());
        Map<String, Object> map_c = eduCompanyService.getMap(qw_c);
        if(!ObjectUtils.isEmpty(map_c)){
            int sumCount = Integer.parseInt(map_c.get("cn").toString());
            divo.setCompanycn(sumCount);
        }else{
            divo.setCompanycn(0);
        }
        //居住证
        QueryWrapper<EduLivePlace> qw_lp = new QueryWrapper<>();
        qw_lp.select("count(1) cn");
        qw_lp.eq("del",0);
        qw_lp.eq("year",vo.getYear());
        Map<String, Object> map_lp = eduLivePlaceService.getMap(qw_lp);
        if(!ObjectUtils.isEmpty(map_lp)){
            int sumCount = Integer.parseInt(map_lp.get("cn").toString());
            divo.setLivePlacecn(sumCount);
        }else{
            divo.setLivePlacecn(0);
        }
        //人社
        QueryWrapper<EduSocialSecurity> qw_ss = new QueryWrapper<>();
        qw_ss.select("count(1) cn");
        qw_ss.eq("del",0);
        qw_ss.eq("year",vo.getYear());
        Map<String, Object> map_ss = eduSocialSecurityService.getMap(qw_ss);
        if(!ObjectUtils.isEmpty(map_ss)){
            int sumCount = Integer.parseInt(map_ss.get("cn").toString());
            divo.setSocialSecuritycn(sumCount);
        }else{
            divo.setSocialSecuritycn(0);
        }

        return divo;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0010", title = "各类别报名预测情况", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public BeforVO getBeforVO(HandConInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        BeforVO bvo = new BeforVO();
        QueryWrapper<EduStudentEnrollBefore> qw_eseb = new QueryWrapper<>();
        qw_eseb.select("config_name")
                .eq("Del",0)
                .eq("year",vo.getYear())
                .in("config_name","A","B","C");
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qw_eseb.inSql("school_id","select org_id from edu_school where del = '0' and School_Category = '"+vo.getSchoolCategory()+"'");
        }
        List<EduStudentEnrollBefore> li_eseb= eduStudentEnrollBeforeService.list(qw_eseb);
        if(!CollectionUtils.isEmpty(li_eseb)){
            Map<String,Long>map1 =  li_eseb.stream().collect(Collectors.groupingBy(EduStudentEnrollBefore::getConfigName,Collectors.counting()));
            if(!ObjectUtils.isEmpty(map1.get("A"))){
                bvo.setBeforAcn(map1.get("A").intValue());
            }else {
                bvo.setBeforAcn(0);
            }
            if(!ObjectUtils.isEmpty(map1.get("B"))){
                bvo.setBeforBcn(map1.get("B").intValue());
            }else {
                bvo.setBeforBcn(0);
            }
            if(!ObjectUtils.isEmpty(map1.get("C"))){
                bvo.setBeforCcn(map1.get("C").intValue());
            }else {
                bvo.setBeforCcn(0);
            }

        }
        return bvo;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0011", title = "学校预报名信息生成", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    @Async("commonTaskExecutor")
    public EnrolYbmVO getEnrolYbm(HandConInVO vo) {
        if (redisHelper.hasKey(getEnrolYbm)) {
            throw new AppException("正在批量生成预报名数据中...");
        }
        redisHelper.set(getEnrolYbm, "1", 3600);
        EnrolYbmVO bvo;
        try {
            if(ObjectUtils.isEmpty(vo.getYear())){
                vo.setYear(eduHelper.thisYear());
            }
            if(ObjectUtils.isEmpty(vo.getAreaCode())){
                CommonVO commonVO=new CommonVO();
                commonVO.setParamKey("area_code");
                String areaCode=commonIntegration.getValueByKey(commonVO);
                vo.setAreaCode(areaCode);
            }


            bvo = new EnrolYbmVO();
            bvo.setYear(vo.getYear());
            bvo.setAreaCode(vo.getAreaCode());

            LambdaQueryWrapper<EduEnrolYbm> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(EduEnrolYbm::getDel,"0");
            lambdaQueryWrapper.eq(EduEnrolYbm::getYear, vo.getYear());
            lambdaQueryWrapper.eq(EduEnrolYbm::getAreaCode, vo.getAreaCode());
            List<EduEnrolYbm> list_del = eduEnrolYbmService.list(lambdaQueryWrapper);
            if(!CollectionUtils.isEmpty(list_del)){
                ybmMapper.delete(lambdaQueryWrapper);
            }
            //生成数据
            //1、edu_student_enroll_pre 有的按这个学校
            List<EnrolYbmVO> list_fir =  getFirEnrolYbmVO(bvo);
            if(!CollectionUtils.isEmpty(list_fir)){
                list_fir.forEach(item->{
                    EduEnrolYbm eduEnrolYbm = new EduEnrolYbm();
                    copyProperties(item,eduEnrolYbm);
                    eduEnrolYbm.setHjType("1");
                    eduEnrolYbmService.save(eduEnrolYbm);
                });
            }
            //2、其他 按config_name 就高取第一条
            QueryWrapper<EduStudentEnrollBefore> qw_eseb = new QueryWrapper<>();
            qw_eseb.select("student_enroll_pre_id")
                    .eq("Del",0)
                    .eq("year",vo.getYear())
                    .notInSql("student_enroll_pre_id","select student_enroll_pre_id from edu_enrol_ybm where del = '0' and year = "+vo.getYear())
                    .groupBy("student_enroll_pre_id");
            List<EduStudentEnrollBefore> li_eseb= eduStudentEnrollBeforeService.list(qw_eseb);
            if(!CollectionUtils.isEmpty(li_eseb)){
                li_eseb.forEach(item->{
                    EnrolYbmVO v1 = new EnrolYbmVO();
                    v1.setYear(vo.getYear()) ;
                    v1.setStudentEnrollPreId(item.getStudentEnrollPreId());
                    v1.setAreaCode(vo.getAreaCode());
                    EnrolYbmVO v2 = getEnrolYbmVO(v1);
                    if(!ObjectUtils.isEmpty(v2)){
                        EduEnrolYbm eduEnrolYbm = new EduEnrolYbm();
                        if(!ObjectUtils.isEmpty(v2)){
                            copyProperties(v2,eduEnrolYbm);
                        }
                        eduEnrolYbm.setHjType("1");
                        eduEnrolYbmService.save(eduEnrolYbm);
                    }

                });
            }
            //_pre有但是_befor表没有的，直接取
            QueryWrapper<EduStudentEnrollPre> qw_pre = new QueryWrapper<>();
            qw_pre.select("idcard","father_Idcard","mother_Idcard","school_id","year"
                            ,"school_category","student_enroll_pre_id","area_code")
                    .eq("Del",0)
                    .isNotNull("school_id")
                    .eq("year",vo.getYear())
                    .notInSql("student_enroll_pre_id","select student_enroll_pre_id from edu_enrol_ybm where del = '0' and year = "+vo.getYear())
                    ;
            List<EduStudentEnrollPre> li_pre = eduStudentEnrollPreService.list(qw_pre);
            if(!CollectionUtils.isEmpty(li_pre)){
                li_pre.forEach(item->{
                    if(!ObjectUtils.isEmpty(item.getSchoolId())) {
                        EduEnrolYbm eduEnrolYbm = new EduEnrolYbm();
                        //判断是否本地户籍
                        int cn = 0;
                        //getFirEnrolYbmSanVO
                        QueryWrapper<EduHousehold> qw_ehh = new QueryWrapper<>();
                        qw_ehh.select("idcard")
                                .eq("Del", 0)
                                .like("address ","东阳")
                                .eq("idcard", item.getIdcard());
                        List<EduHousehold> l1 = eduHouseholdService.list(qw_ehh);
                        if (l1.size() >= 1) {
                            cn = 1;
                        } else {
                            EnrolYbmFcVO fcvo = new EnrolYbmFcVO();
                            fcvo.setYear(vo.getYear());
                            fcvo.setAreaCode(vo.getAreaCode());
                            fcvo.setIdcard(item.getIdcard());
                            fcvo.setFatherIdcard(item.getFatherIdcard());
                            fcvo.setMotherIdcard(item.getMotherIdcard());
                            List<EnrolYbmFcVO> l2 = getFirEnrolYbmSanVO(fcvo);
                            if (l2.size() >= 1) {
                                cn = 1;
                            }
                        }
                        copyProperties(item, eduEnrolYbm);
                        EduSchoolVO eduSchool = eduSchoolService.getDetail(item.getSchoolId());
                        if (eduSchool != null) {
                            eduEnrolYbm.setSchoolNature(eduSchool.getSchoolNature());
                            if(!ObjectUtils.isEmpty(eduSchool.getStreet())){
                                GetDictVO gdvo = new GetDictVO();
                                gdvo.setDictField(eduSchool.getStreet());
                                gdvo.setAstype("2");
                                eduEnrolYbm.setStreet(getDictName(gdvo).getDictValue());
                            }else{
                                eduEnrolYbm.setStreet("1");
                            }
                            eduEnrolYbm.setSchoolName(eduSchool.getSchoolName());
                        }
                        if (cn == 1) {
                            eduEnrolYbm.setHjType("1");
                        } else {
                            eduEnrolYbm.setHjType("0");
                        }
                        eduEnrolYbmService.save(eduEnrolYbm);
                    }
                });

            }
        } catch (AppException e) {
            throw new AppException( e.getMessage());
        } finally {
            redisHelper.del(getEnrolYbm);
        }


        redisHelper.del(getEnrolYbm);
        return bvo;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0012", title = "按区县学校预报名信息", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public List<EnrolYbmQxVO> getEnrolYbmQx(HandConInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        QueryWrapper<EduEnrolYbm> qw_eseb = new QueryWrapper<>();
        qw_eseb.select("street")
                .eq("year",vo.getYear());
        if(!ObjectUtils.isEmpty(vo.getConfigName())){
            qw_eseb.eq("config_name",vo.getConfigName());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qw_eseb.eq("school_Category",vo.getSchoolCategory());
        }
        List<EduEnrolYbm> li_eseb= eduEnrolYbmService.list(qw_eseb);
        List<EnrolYbmQxVO> li_qx = new ArrayList<>();
        if(!CollectionUtils.isEmpty(li_eseb)){
            Map<String,Long> map = li_eseb.stream().filter(item-> StringUtil.isNotBlank(item.getStreet())).collect(Collectors.groupingBy(EduEnrolYbm::getStreet,Collectors.counting()));
            for (String key : map.keySet()) {
                EnrolYbmQxVO qxvo = new EnrolYbmQxVO();
                Long value = map.get(key);
                qxvo.setStreet(key);
                qxvo.setCount(value.intValue());
                li_qx.add(qxvo);
            }

        }else{
            throw new AppException("未查询到相应数据");
        }
        li_qx.sort(Comparator.comparing(EnrolYbmQxVO::getCount).reversed());
        return li_qx;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0013", title = "按学校学校预报名信息", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public PageInfo<EnrolYbmXxVO> getEnrolYbmXx(HandConInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }

        if (vo.getPageNum() == null || vo.getPageSize() == null || vo.getPageSize() == 0) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(10);
        }else{
            vo.setPageNum(vo.getPageNum()+1);
        }
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<EnrolYbmXxVO> li_xx = eduEnrolYbmService.getEnrolYbmXxList(vo);
        if(CollectionUtils.isEmpty(li_xx)){
            throw new AppException("未找到对应戴数据");
        }
        return new PageInfo<>(li_xx);
    }


    @Override
    @OpApi(funcCode = "EduAnalysisXq0014", title = "预报名信息汇总", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public HandConVO getEnrolYbmHz(HandConInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        HandConVO eyvo = new HandConVO();
        //学校总数
        QueryWrapper<EduSchool> qw_sc = new QueryWrapper<>();
        qw_sc.select("org_id")
                .eq("del","0")
                .eq("area_code",vo.getAreaCode());
        List<EduSchool> li_sc= eduSchoolService.list(qw_sc);
        eyvo.setSchoolCount(li_sc.size());
        //总学位数
        eyvo.setEnrollCount(0);
        eyvo.setEnrollCountBe(0);
        QueryWrapper<EduSchoolConfig> qw_con = new QueryWrapper<>();
        qw_con.select("sum(enrolment) enrolment","year")
                .eq("del","0")
                .in("year",vo.getYear(),vo.getYear()-1)
                .eq("area_code",vo.getAreaCode())
                .groupBy("year");
        List<EduSchoolConfig> li_con = eduSchoolConfigService.list(qw_con);
        for(EduSchoolConfig con:li_con){
            if(vo.getYear().equals(con.getYear())){
                eyvo.setEnrollCount(con.getEnrolment());
            }else{
                eyvo.setEnrollCountBe(con.getEnrolment());
            }
        }
        if(eyvo.getEnrollCount()==0){
            eyvo.setEnrollCount(eyvo.getEnrollCountBe());
        }



        //预报名总数
        eyvo.setBeforCount(0);
        eyvo.setBeforBeCount(0);
        QueryWrapper<EduStudentEnrollPre> qw_befor = new QueryWrapper<>();
        qw_befor.select("year")
                .eq("del","0")
                .in("year",vo.getYear(),vo.getYear()-1)
                .eq("area_code",vo.getAreaCode());
        List<EduStudentEnrollPre> li_befor = eduStudentEnrollPreService.list(qw_befor);
        if(!CollectionUtils.isEmpty(li_befor)){
            Map<Integer,Long> map1 = li_befor.stream().
                    filter(item-> StringUtil.isNotBlank(item.getYear()+"")).
                    collect(Collectors.groupingBy(EduStudentEnrollPre::getYear,Collectors.counting()));
            for (int key : map1.keySet()) {
                Long value = map1.get(key);
                if(vo.getYear().equals(key)){
                    eyvo.setBeforCount(value.intValue());
                }else{
                    eyvo.setBeforBeCount(value.intValue());
                }
            }
        }
        if(eyvo.getBeforCount()==0){
            eyvo.setBeforCount(eyvo.getBeforBeCount());
        }
        return eyvo;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0015", title = "学生占比", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public StuEnrollXszbVO getStuEnrollXszb(StuEnrollInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        StuEnrollXszbVO serxvo = new StuEnrollXszbVO();
        int Mcount = 0;
        int Wcount = 0;
        int SchoolCategoryXx = 0;
        int SchoolCategoryZx = 0;
        QueryWrapper<EduStudentEnroll> qw_enroll_sex = new QueryWrapper<>();
        qw_enroll_sex.select("sex","count(DISTINCT idcard) serial_num")
                .eq("del","0")
                .eq("year",vo.getYear())
                .eq("area_code",vo.getAreaCode())
                .groupBy("sex");
        List<EduStudentEnroll> li_enroll_sex= eduStudentEnrollService.list(qw_enroll_sex);
        if(!CollectionUtils.isEmpty(li_enroll_sex)){
            for(EduStudentEnroll str:li_enroll_sex){
                if("1".equals(str.getSex())){
                    Mcount = Mcount+ str.getSerialNum();
                }else{
                    Wcount = Wcount+ str.getSerialNum();
                }

            }
            serxvo.setWcount(Mcount);
            serxvo.setMcount(Wcount);

        }else{
            serxvo.setWcount(0);
            serxvo.setMcount(0);
        }

        QueryWrapper<EduStudentEnroll> qw_enroll_cat = new QueryWrapper<>();
        qw_enroll_cat.select("school_category","count(DISTINCT idcard) serial_num")
                .eq("del","0")
                .eq("year",vo.getYear())
                .eq("area_code",vo.getAreaCode())
                .groupBy("school_category");
        List<EduStudentEnroll> li_enroll_cat= eduStudentEnrollService.list(qw_enroll_cat);
        if(!CollectionUtils.isEmpty(li_enroll_cat)){
            for(EduStudentEnroll str:li_enroll_cat){
                if("2".equals(str.getSchoolCategory())){
                    SchoolCategoryXx = SchoolCategoryXx+str.getSerialNum();
                }else{
                    SchoolCategoryZx = SchoolCategoryZx+str.getSerialNum();
                }
            }
            serxvo.setSchoolCategoryZx(SchoolCategoryZx);
            serxvo.setSchoolCategoryXx(SchoolCategoryXx);
        }else{
            serxvo.setSchoolCategoryZx(0);
            serxvo.setSchoolCategoryXx(0);
        }
        return serxvo;
    }


    @Override
    @OpApi(funcCode = "EduAnalysisXq0016", title = "实时报名汇总信息", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public StuEnrollHzxxVO getStuEnrollHzxx(StuEnrollInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        StuEnrollHzxxVO hzxxvo = new StuEnrollHzxxVO();
        //报名数据
        QueryWrapper<EduStudentEnroll> qw_bm = new QueryWrapper<>();
        qw_bm.select("school_category","count(DISTINCT idcard) serial_num")
                .eq("del","0")
                .eq("year",vo.getYear())
                .in("school_category",2,3)
                .eq("area_code",vo.getAreaCode())
                .groupBy("school_category");
        List<EduStudentEnroll> li_bm= eduStudentEnrollService.list(qw_bm);
        if(!CollectionUtils.isEmpty(li_bm)){
            for(EduStudentEnroll str:li_bm){
                if("2".equals(str.getSchoolCategory())){
                    hzxxvo.setXxbmrs(str.getSerialNum());
                }else{
                    hzxxvo.setZxbmrs(str.getSerialNum());
                }
            }
        }
        //录取人数
        QueryWrapper<EduStudentEnroll> qw_lq = new QueryWrapper<>();
        qw_lq.select("DISTINCT idcard")
                .eq("del","0")
                .eq("year",vo.getYear())
                .eq("enroll_status","2")
                .in("school_category",2,3)
                .eq("area_code",vo.getAreaCode());
        List<EduStudentEnroll> li_lq= eduStudentEnrollService.list(qw_lq);
        if(!CollectionUtils.isEmpty(li_lq)){
            hzxxvo.setYlq(li_lq.size());
        }
        hzxxvo.setYbm(hzxxvo.getXxbmrs()+hzxxvo.getZxbmrs());

        //总学位数
        QueryWrapper<EduSchoolConfig> qwcon = new QueryWrapper<>();
        qwcon.select("school_category","sum(enrolment) enrolment")
                .eq("del","0")
                .eq("year",vo.getYear())
                .in("school_category",2,3)
                .eq("area_code",vo.getAreaCode())
                .groupBy("school_category");
        List<EduSchoolConfig> li_pre= eduSchoolConfigService.list(qwcon);
        int zxws = 0;//总学位数
        int xxxw = 0;//小学学位数
        int zxxw = 0;//中学学位数
        for(EduSchoolConfig convo:li_pre){
            zxws = zxws+convo.getEnrolment();
            if("2".equals(convo.getSchoolCategory())){
                xxxw=convo.getEnrolment();
            }else{
                zxxw=convo.getEnrolment();
            }
        }
        hzxxvo.setXxxws(xxxw);//小学剩余学位数 小学学位数-小学已录取报名数
        hzxxvo.setZxxws(zxxw);
        hzxxvo.setSyxw(zxws-hzxxvo.getYlq());//剩余学位数 学位数-已录取
        return hzxxvo;
    }
    @Override
    @OpApi(funcCode = "EduAnalysisXq0017", title = "学校预测预报名信息生成", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    @Async("commonTaskExecutor")
    public EnrolYbmVO getEnrolYbmCalculate(HandConInVO vo) {
        if (redisHelper.hasKey(getEnrolYbm)) {
            throw new AppException("正在批量生成预报名数据中...");
        }
        redisHelper.set(getEnrolYbm, "1", 3600);
        EnrolYbmVO bvo;
        try {
            if(ObjectUtils.isEmpty(vo.getYear())){
                vo.setYear(eduHelper.thisYear());
            }
            if(ObjectUtils.isEmpty(vo.getAreaCode())){
                CommonVO commonVO=new CommonVO();
                commonVO.setParamKey("area_code");
                String areaCode=commonIntegration.getValueByKey(commonVO);
                vo.setAreaCode(areaCode);
            }
            bvo = new EnrolYbmVO();
            bvo.setYear(vo.getYear());
            bvo.setAreaCode(vo.getAreaCode());

            LambdaQueryWrapper<EduEnrolYbmCalculate> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(EduEnrolYbmCalculate::getDel,"0");
            lambdaQueryWrapper.eq(EduEnrolYbmCalculate::getYear, vo.getYear());
            lambdaQueryWrapper.eq(EduEnrolYbmCalculate::getAreaCode, vo.getAreaCode());
            List<EduEnrolYbmCalculate> list_del = eduEnrolYbmCalculateService.list(lambdaQueryWrapper);
            if(!CollectionUtils.isEmpty(list_del)){
                ybmCalculateMapper.delete(lambdaQueryWrapper);
            }

            //生成数据
            //1、edu_student_enroll_pre 有的按这个学校
            bvo.setConfigName("A");
            List<EnrolYbmVO> list_firA =  getFirEnrolYbmCalculateVO(bvo);
            if(!CollectionUtils.isEmpty(list_firA)){
                list_firA.forEach(item->{
                    EduEnrolYbmCalculate eduEnrolYbm = new EduEnrolYbmCalculate();
                    copyProperties(item,eduEnrolYbm);
                    eduEnrolYbm.setHjType("1");
                    eduEnrolYbmCalculateService.save(eduEnrolYbm);
                });
            }
            bvo.setConfigName("B");
            List<EnrolYbmVO> list_firB =  getFirEnrolYbmCalculateVO(bvo);
            if(!CollectionUtils.isEmpty(list_firB)){
                list_firB.forEach(item->{
                    EduEnrolYbmCalculate eduEnrolYbm = new EduEnrolYbmCalculate();
                    copyProperties(item,eduEnrolYbm);
                    eduEnrolYbm.setHjType("1");
                    eduEnrolYbmCalculateService.save(eduEnrolYbm);
                });
            }
            bvo.setConfigName("C");
            List<EnrolYbmVO> list_firC =  getFirEnrolYbmCalculateVO(bvo);
            if(!CollectionUtils.isEmpty(list_firC)){
                list_firC.forEach(item->{
                    EduEnrolYbmCalculate eduEnrolYbm = new EduEnrolYbmCalculate();
                    copyProperties(item,eduEnrolYbm);
                    eduEnrolYbm.setHjType("1");
                    eduEnrolYbmCalculateService.save(eduEnrolYbm);
                });
            }
            bvo.setConfigName("特殊户口");
            List<EnrolYbmVO> list_firO =  getFirEnrolYbmCalculateVO(bvo);
            if(!CollectionUtils.isEmpty(list_firO)){
                list_firO.forEach(item->{
                    EduEnrolYbmCalculate eduEnrolYbm = new EduEnrolYbmCalculate();
                    copyProperties(item,eduEnrolYbm);
                    eduEnrolYbm.setHjType("1");
                    eduEnrolYbmCalculateService.save(eduEnrolYbm);
                });
            }
            //2、其他 按config_name 就高取第一条
            QueryWrapper<EduStudentEnrollCalculate> qw_eseb = new QueryWrapper<>();
            qw_eseb.select("student_enroll_pre_id")
                    .eq("Del",0)
                    .eq("year",vo.getYear())
                    .notInSql("student_enroll_pre_id","select student_enroll_pre_id from edu_enrol_ybm_Calculate where del = '0' and year = "+vo.getYear())
                    .groupBy("student_enroll_pre_id");
            List<EduStudentEnrollCalculate> li_eseb= eduStudentEnrollCalculateService.list(qw_eseb);
            if(!CollectionUtils.isEmpty(li_eseb)){
                li_eseb.forEach(item->{
                    EnrolYbmVO v1 = new EnrolYbmVO();
                    v1.setYear(vo.getYear()) ;
                    v1.setStudentEnrollPreId(item.getStudentEnrollPreId());
                    v1.setAreaCode(vo.getAreaCode());
                    EnrolYbmVO v2 = getEnrolYbmCalculateVO(v1);
                    if(!ObjectUtils.isEmpty(v2)){
                        EduEnrolYbmCalculate eduEnrolYbm = new EduEnrolYbmCalculate();
                        if(!ObjectUtils.isEmpty(v2)){
                            copyProperties(v2,eduEnrolYbm);
                        }

                        eduEnrolYbm.setHjType("1");
                        eduEnrolYbmCalculateService.save(eduEnrolYbm);
                    }

                });
            }

            //_pre有但是_befor表没有的，直接取
            QueryWrapper<EduStudentEnrollPre> qw_pre = new QueryWrapper<>();
            qw_pre.select("idcard","father_Idcard","mother_Idcard","school_id","year"
                            ,"school_category","student_enroll_pre_id","area_code")
                    .eq("Del",0)
                    .isNotNull("school_id")
                    .eq("year",vo.getYear())
                    .notInSql("student_enroll_pre_id","select student_enroll_pre_id from edu_enrol_ybm_Calculate where del = '0' and year = "+vo.getYear())
            ;
            List<EduStudentEnrollPre> li_pre = eduStudentEnrollPreService.list(qw_pre);
            if(!CollectionUtils.isEmpty(li_pre)){
                li_pre.forEach(item->{
                    if(!ObjectUtils.isEmpty(item.getSchoolId())){
                        EduEnrolYbmCalculate eduEnrolYbm = new EduEnrolYbmCalculate();
                        //判断是否本地户籍
                        int cn = 0;
                        //getFirEnrolYbmSanVO
                        QueryWrapper<EduHousehold> qw_ehh = new QueryWrapper<>();
                        qw_ehh.select("idcard")
                                .eq("Del",0)
                                .like("address ","东阳")
                                .eq("idcard",item.getIdcard());
                        List<EduHousehold> l1 = eduHouseholdService.list(qw_ehh);
                        if(l1.size()>=1){
                            cn=1;
                        }else{
                            EnrolYbmFcVO fcvo = new EnrolYbmFcVO();
                            fcvo.setYear(vo.getYear());
                            fcvo.setAreaCode(vo.getAreaCode());
                            fcvo.setIdcard(item.getIdcard());
                            fcvo.setFatherIdcard(item.getFatherIdcard());
                            fcvo.setMotherIdcard(item.getMotherIdcard());
                            List<EnrolYbmFcVO> l2 = getFirEnrolYbmSanVO(fcvo);
                            if(l2.size()>=1){
                                cn=1;
                            }
                        }
                        copyProperties(item,eduEnrolYbm);
                        EduSchoolVO eduSchool = eduSchoolService.getDetail(item.getSchoolId());
                        if(eduSchool!=null){
                            eduEnrolYbm.setSchoolNature(eduSchool.getSchoolNature());
                            if(!ObjectUtils.isEmpty(eduSchool.getStreet())){
                                GetDictVO gdvo = new GetDictVO();
                                gdvo.setDictField(eduSchool.getStreet());
                                gdvo.setAstype("2");
                                eduEnrolYbm.setStreet(getDictName(gdvo).getDictValue());
                            }else{
                                eduEnrolYbm.setStreet("1");
                            }
                            eduEnrolYbm.setSchoolName(eduSchool.getSchoolName());
                            eduEnrolYbm.setSchoolId(item.getSchoolId());
                        }else{
                            eduEnrolYbm.setStreet("1");
                            eduEnrolYbm.setSchoolName("1");
                            eduEnrolYbm.setSchoolName("a");
                        }
                        if(cn==1){
                            eduEnrolYbm.setHjType("1");
                        }else{
                            eduEnrolYbm.setHjType("0");
                        }
                        eduEnrolYbmCalculateService.save(eduEnrolYbm);
                    }
                });
            }
        } catch (AppException e) {
            throw new AppException( e.getMessage());
        } finally {
            redisHelper.del(getEnrolYbm);
        }
        redisHelper.del(getEnrolYbm);
        return bvo;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0018", title = "学校预报名信息生成批处理结束", funcType = FuncTypeEnum.other,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public void clearCacheCreate(BaseVO vo) {
        redisHelper.del(getEnrolYbm);
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0019", title = "预报名的信息列表", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public PageInfo<EnrolYbmXxRyVO> getEnrolYbmXxRy(EnrolYbmXxRyInVO vo) {
        if(ObjectUtils.isEmpty(vo.getSchoolId())){
            throw new AppException("学校id不能为空");
        }
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }


        if (vo.getPageNum() == null || vo.getPageSize() == null || vo.getPageSize() == 0) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(10);
        }else{
            vo.setPageNum(vo.getPageNum()+1);
        }
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<EnrolYbmXxRyVO> li = getEnrolYbmXxRyVO(vo);
        return new PageInfo<>(li);
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0020", title = "报名人数", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public StuEnrollBmrsVO getStuEnrollBmrs(StuEnrollInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        StuEnrollBmrsVO bmrsvo = new StuEnrollBmrsVO();
        QueryWrapper<EduStudentEnroll> qw_enroll = new QueryWrapper<>();
        qw_enroll.select("source","count(DISTINCT idcard) serial_num")
                .eq("Del", 0)
                .eq("year", vo.getYear())
                .eq("area_code",vo.getAreaCode());
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qw_enroll.eq("school_category",vo.getSchoolCategory());
        }
        qw_enroll.groupBy("source");
        List<EduStudentEnroll> l1 = eduStudentEnrollService.list(qw_enroll);
        int xs = 0;
        int xx = 0;
        if(!CollectionUtils.isEmpty(l1)){
            for(EduStudentEnroll str:l1){
                if("2".equals(str.getSource())){
                    xs = xs+str.getSerialNum();
                }else{
                    xx = xx+str.getSerialNum();
                }
            }
        }
        bmrsvo.setXsbm(xs);
        bmrsvo.setXxbm(xx);
        //实时报名人数趋势
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        String dt = formatter.format(date);
        List<StuEnrollBmqsVO> bmqsList = new ArrayList<>();
        QueryWrapper<EduStudentEnroll> qw_enroll_jt = new QueryWrapper<>();
        qw_enroll_jt.select("HOUR(create_time) as create_name","count(DISTINCT idcard) as year")
                .eq("Del", 0)
                .eq("year", vo.getYear())
                .eq("area_code",vo.getAreaCode())
                .eq("date_format(create_time,'%Y%m%d')",dt);
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qw_enroll_jt.eq("school_category",vo.getSchoolCategory());
        }
        qw_enroll_jt.groupBy("HOUR(create_time)");
        List<EduStudentEnroll> l1_jt = eduStudentEnrollService.list(qw_enroll_jt);
        for(EduStudentEnroll en:l1_jt){
            StuEnrollBmqsVO svo = new StuEnrollBmqsVO();
            svo.setXzhou(en.getCreateName());
            svo.setYzhou(en.getYear());
            bmqsList.add(svo);
        }
        bmrsvo.setBmqsList(bmqsList);
        return bmrsvo;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0021", title = "乡镇街道排名", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public List<StuEnrollXzjdpmVO> getStuEnrollXzjdpm(StuEnrollInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        return getStuEnrollXzjdpmVO(vo);
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0022", title = "单个学校信息", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public StuEnrollDgxxVO getStuEnrollDgxx(StuEnrollDgxxInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getSchoolId())){
            throw new AppException("学校ID不能为空");
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        StuEnrollDgxxVO dgxxvo = new StuEnrollDgxxVO();
        EduSchoolVO school = eduSchoolService.getDetail(vo.getSchoolId());
        if(!ObjectUtils.isEmpty(school)){
            dgxxvo.setSchoolNature(school.getSchoolNature());
            dgxxvo.setSchoolName(school.getSchoolName());
            dgxxvo.setSchoolCategory(school.getSchoolCategory());
        }
        SchoolAddressQueryVO saqvo = new SchoolAddressQueryVO();
        saqvo.setSchoolId(vo.getSchoolId());
        List<EduAddressVO> scaddressList =  eduAddressSchoolService.getAddress(saqvo);
        if(!CollectionUtils.isEmpty(scaddressList)){
            dgxxvo.setAddressName(scaddressList.get(0).getAddressName());
        }
        dgxxvo.setSchoolId(vo.getSchoolId());
        //已报名
        if (vo.getPageNum() == null || vo.getPageSize() == null || vo.getPageSize() == 0) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(10);
        }else{
            vo.setPageNum(vo.getPageNum()+1);
        }
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        QueryWrapper<EduStudentEnroll> qw_bm = new QueryWrapper<>();
        qw_bm.select("enroll_status","config_name","full_name","idcard","sex","birth_ymd","address")
                .eq("del","0")
                .eq("year",vo.getYear())
                .eq("school_id",vo.getSchoolId())
                .in("school_category",2,3)
                .eq("area_code",vo.getAreaCode());
        List<EduStudentEnroll> li_bm= eduStudentEnrollService.list(qw_bm);
        dgxxvo.setYbm(li_bm.size());
        int ylq = 0;
        if(!CollectionUtils.isEmpty(li_bm)){
            Map<String,Long> map = li_bm.stream().filter(item-> StringUtil.isNotBlank(item.getEnrollStatus())).collect(Collectors.groupingBy(EduStudentEnroll::getEnrollStatus,Collectors.counting()));
            if(!ObjectUtils.isEmpty(map)){
                for(String key : map.keySet()){
                    if("2".equals(key)){
                        //已录取
                        ylq = ylq+map.get(key).intValue();
                    }
                }
            }
        }
        //计划招生人数
        QueryWrapper<EduSchoolConfig> qwcon = new QueryWrapper<>();
        qwcon.select("sum(enrolment) enrolment")
                .eq("del","0")
                .eq("year",vo.getYear())
                .eq("school_id",vo.getSchoolId())
                .in("school_category",2,3)
                .eq("area_code",vo.getAreaCode());
        Map<String, Object> map = eduSchoolConfigService.getMap(qwcon);
        if (!ObjectUtils.isEmpty(map)) {
            dgxxvo.setJhzsrs(Integer.valueOf(map.get("enrolment").toString()));
        }
        //剩余学位
        dgxxvo.setSyxw(dgxxvo.getJhzsrs()-ylq);
        //预报名人数
        QueryWrapper<EduStudentEnrollPre> qw_befor = new QueryWrapper<>();
        qw_befor.select("year")
                .eq("del","0")
                .eq("school_id",vo.getSchoolId())
                .in("year",vo.getYear(),vo.getYear()-1)
                .eq("area_code",vo.getAreaCode());
        List<EduStudentEnrollPre> li_befor = eduStudentEnrollPreService.list(qw_befor);
        dgxxvo.setYbmrs(li_befor.size());
        //报名学生明细 31
        List<StuEnrollBmmxVO> bmmxList = new ArrayList<>();
        for(EduStudentEnroll esevo : li_bm){
            StuEnrollBmmxVO bmmxVO = new StuEnrollBmmxVO();
            bmmxVO.setConfigName(esevo.getConfigName());
            bmmxVO.setFullName(esevo.getFullName());
            bmmxVO.setSex(esevo.getSex());
            bmmxVO.setIdcard(esevo.getIdcard());
            //年龄
            String csrq = esevo.getBirthYmd();
            LocalDate date1 = LocalDate.now();
            DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyyMMdd");
            String dqrq = date1.format(formatter1);
            int nl1 = Integer.parseInt(StringUtils.substring(dqrq,0,4))-Integer.parseInt(StringUtils.substring(csrq,0,4));
            int nl2 = Integer.parseInt(StringUtils.substring(dqrq,4,6))-Integer.parseInt(StringUtils.substring(csrq,4,6));
            if(nl2>=0){
                bmmxVO.setNl(nl1);
            }else{
                bmmxVO.setNl(nl1-1);
            }
            //地址
            bmmxVO.setAddress(esevo.getAddress());
            bmmxList.add(bmmxVO);
        }

//        List listPage = page(bmmxList,vo.getPageNum(),vo.getPageSize());
        PageInfo<StuEnrollBmmxVO> pageInfo = new PageInfo<>(bmmxList);
//        bmmxList = PagerUtil.parsePagerVo(listPage, pageInfo).getList();
        dgxxvo.setBmmxList(pageInfo.getList());

        return dgxxvo;
    }
    @Override
    @OpApi(funcCode = "EduAnalysisXq0023", title = "学校画像", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public StuEnrollXxhxVO getStuEnrollXxhx(StuEnrollDgxxInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getSchoolId())){
            throw new AppException("学校id不能为空");
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        StuEnrollXxhxVO xzvo = new StuEnrollXxhxVO();
        EduSchoolHxKeyVO hxkeyvo = new EduSchoolHxKeyVO();
        hxkeyvo.setSchoolId(vo.getSchoolId());
        EduSchoolHx  eduSchoolHx = eduSchoolHxService.getById(hxkeyvo);
        EduSchoolVO schoolvo =  eduSchoolService.getDetail(vo.getSchoolId());
        if(!ObjectUtils.isEmpty(eduSchoolHx)){
            copyProperties(eduSchoolHx,xzvo);
        }
        if(!ObjectUtils.isEmpty(schoolvo)){
            copyProperties(schoolvo,xzvo);
        }


        //已报名
        QueryWrapper<EduStudentEnroll> qw_bm = new QueryWrapper<>();
        qw_bm.select("enroll_status")
                .eq("del","0")
                .eq("year",vo.getYear())
                .eq("school_id",vo.getSchoolId())
                .in("school_category",2,3)
                .eq("area_code",vo.getAreaCode());
        List<EduStudentEnroll> li_bm= eduStudentEnrollService.list(qw_bm);
        xzvo.setYbm(li_bm.size());
        //计划招生人数
        QueryWrapper<EduSchoolConfig> qwcon = new QueryWrapper<>();
        qwcon.select("sum(enrolment) enrolment")
                .eq("del","0")
                .eq("year",vo.getYear())
                .eq("school_id",vo.getSchoolId())
                .in("school_category",2,3)
                .eq("area_code",vo.getAreaCode());
        Map<String, Object> mapcon = eduSchoolConfigService.getMap(qwcon);
        if (!ObjectUtils.isEmpty(mapcon)) {
            xzvo.setJhzsrs(Integer.valueOf(mapcon.get("enrolment").toString()));
        }
        //预报名人数
        QueryWrapper<EduStudentEnrollPre> qw_befor = new QueryWrapper<>();
        qw_befor.select("year")
                .eq("del","0")
                .eq("school_id",vo.getSchoolId())
                .in("year",vo.getYear(),vo.getYear()-1)
                .eq("area_code",vo.getAreaCode());
        List<EduStudentEnrollPre> li_befor = eduStudentEnrollPreService.list(qw_befor);
        xzvo.setYbmrs(li_befor.size());



        //历年招生趋势
        List<StuEnrollLnzsqsVO> lnzsqList = new ArrayList<>();
        QueryWrapper<EduStudentEnroll> qwyx = new QueryWrapper<>();
        qwyx.select("year","case when config_name ='A' then 'A' when config_name ='B' then 'B' when config_name ='C' then 'C' else 'qt' end as config_name")
                .eq("Del",0)
                .in("school_category",2,3)
                .between("year",vo.getYear()-5,vo.getYear())
                .eq("school_id",vo.getSchoolId());
        List<EduStudentEnroll> yxlist= eduStudentEnrollService.list(qwyx);
        if(!CollectionUtils.isEmpty(yxlist)){
            Map<String,Map<Integer,Long>> map = yxlist.stream().filter(item->
                    //做非空判断
            StringUtil.isNotBlank(item.getYear()+"")&&
            StringUtil.isNotBlank(item.getConfigName())
            ).collect(Collectors.groupingBy(EduStudentEnroll::getConfigName,Collectors.groupingBy(EduStudentEnroll::getYear,Collectors.counting())));
            for(String key: map.keySet()){
                StuEnrollLnzsqsVO lnvo = new StuEnrollLnzsqsVO();
                lnvo.setFl(key);
                Map<Integer,Long> map1 = map.get(key);
                List<StuEnrollLnzsqsTjVO> lnzsqsTjList = new ArrayList<>();
                for(int key1:map1.keySet()){
                    StuEnrollLnzsqsTjVO tjvo = new StuEnrollLnzsqsTjVO();
                    tjvo.setYear(key1);
                    tjvo.setCount(map1.get(key1).intValue());
                    lnzsqsTjList.add(tjvo);
                }
                lnvo.setLnzsqsTjList(lnzsqsTjList);
                lnzsqList.add(lnvo);
            }
        }
        xzvo.setLnzsqList(lnzsqList);
        //各类别录取率
        StuEnrollGlblqlVO segvo = getStuEnrollGlblqlVO(vo.getSchoolId(),vo.getYear(),vo.getAreaCode());
        xzvo.setSegvo(segvo);

        //学区内的小区 30接口
        SchoolAddressQueryVO saqvo = new SchoolAddressQueryVO();
        saqvo.setSchoolId(vo.getSchoolId());
        if (vo.getPageNum() == null || vo.getPageSize() == null || vo.getPageSize() == 0) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(10);
        }else{
            vo.setPageNum(vo.getPageNum()+1);
        }
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<EduAddressVO> getAddressNo = eduAddressSchoolService.getAddress(saqvo);

        List<StuEnrollXxhxXqnxqVO> xqnxqList = Convert.toList(StuEnrollXxhxXqnxqVO.class, getAddressNo);
        PageInfo<StuEnrollXxhxXqnxqVO> pageInfo = new PageInfo<>(xqnxqList);

//        List listPage = page(xqnxqList,vo.getPageNum(),vo.getPageSize());
//        PageInfo<EnrolYbmXxRyVO> pageInfo = new PageInfo(xqnxqList);
//        xqnxqList = PagerUtil.parsePagerVo(listPage, pageInfo).getList();
        xzvo.setXqnxqList(pageInfo.getList());

        return xzvo;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0024", title = "学位调剂人员生成", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public StuEnrollXxhxVO getStuEnrollxstjsc(StuEnrollInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        List<StuEnrollTjVO> tjList = eduSchoolXwtjService.getStuEnrollxstjscVO(vo);
        for(StuEnrollTjVO tjvo:tjList){
            EduSchoolVO school = eduSchoolService.getDetail(tjvo.getSchoolId());
            QueryWrapper<EduStudentEnroll> qwyx = new QueryWrapper<>();
            qwyx.eq("Del",0)
                    .eq("school_nature","0")
                    .eq("enroll_status","2")
                    .in("school_category",2,3)
                    .eq("year",vo.getYear())
                    .eq("school_id",tjvo.getSchoolId());
            List<EduStudentEnroll> yxlist= eduStudentEnrollService.list(qwyx);
            for(EduStudentEnroll esevo:yxlist){
                EduSchoolXwtj eduSchoolXwtj = new EduSchoolXwtj();
                copyProperties(esevo,eduSchoolXwtj);
                copyProperties(school,eduSchoolXwtj);
                eduSchoolXwtjService.save(eduSchoolXwtj);
            }
        }
        return null;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0025", title = "学位调剂", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public StuEnrollXwdtjReVO getStuEnrollXwtj(StuEnrollXwdtjReInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        if(StringUtils.isBlank(vo.getType())){
            vo.setType("1");
        }


        StuEnrollXwdtjReVO sexwvo = new StuEnrollXwdtjReVO();
        StuEnrollGlblqlVO glblqvo = getStuEnrollGlblqlVO("",vo.getYear(),vo.getAreaCode());
        sexwvo.setStuEnrollGlblqlVO(glblqvo);
        QueryWrapper<EduSchoolXwtj> qwyx = new QueryWrapper<>();
        qwyx.select("street","CONCAT(school_id,'|',school_name) as  school_name","target_school_zhid",
                        "target_school_fcid","target_school_hjid","school_category")
                .eq("Del",0)
                .in("school_category",2,3)
                .eq("year",vo.getYear())
                .eq("area_code",vo.getAreaCode());
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qwyx.eq("school_category",vo.getSchoolCategory());
        }
        List<EduSchoolXwtj> yxlist= eduSchoolXwtjService.list(qwyx);

        StuEnrollTjhzVO stuEnrollTjhzVO = new StuEnrollTjhzVO();
        stuEnrollTjhzVO.setDtjxx(yxlist.size());
        int xxrs = 0;
        int zxrs = 0;

        List<StuEnrollXxtjVO> xxdtjxxList = new ArrayList<>();
        List<StuEnrollXwtjReVO> xxtjxxList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(yxlist)){
            Map<String,Map<String,Long>> map = yxlist.stream().filter(item->
                    //做非空判断
                    StringUtil.isNotBlank(item.getStreet())&&
                            StringUtil.isNotBlank(item.getSchoolName())
            ).collect(Collectors.groupingBy(EduSchoolXwtj::getStreet,Collectors.groupingBy(EduSchoolXwtj::getSchoolName,Collectors.counting())));
            for(String key:map.keySet()){
                StuEnrollXxtjVO xxtjVO = new StuEnrollXxtjVO();
//                xxtjVO.setStreet(key);
                GetDictVO gdvo = new GetDictVO();
                gdvo.setDictField(key);
                gdvo.setAstype("2");
                xxtjVO.setStreet(getDictName(gdvo).getDictValue());
                Map<String,Long> map1 = map.get(key);
                for(String key1: map1.keySet()){
                    int value = map1.get(key1).intValue();
                    xxtjVO.setSchoolId(StringUtils.substringBefore(key1,"|"));
                    xxtjVO.setSchoolName(StringUtils.substringAfter(key1, "|"));
                    xxtjVO.setSchoolTj(value);
                    xxdtjxxList.add(xxtjVO);
                }

            }
        }

        QueryWrapper<EduStudentTj> qw_tj = new QueryWrapper<>();
        qw_tj.select("CONCAT(from_school_id,'|',from_school_name) as  from_school_name ",
                        "CONCAT(to_school_id,'|',to_school_name) as  to_school_name")
                .eq("Del",0)
                .eq("year",vo.getYear());
        List<EduStudentTj> tjList = eduStudentTjService.list(qw_tj);
        if(!CollectionUtils.isEmpty(tjList)){
            Map<String,Map<String,Long>> maptj = tjList.stream().filter(item->
                    //做非空判断
                    StringUtil.isNotBlank(item.getFromSchoolName()+"")&&
                            StringUtil.isNotBlank(item.getToSchoolName())
            ).collect(Collectors.groupingBy(EduStudentTj::getFromSchoolName,Collectors.groupingBy(EduStudentTj::getToSchoolName,Collectors.counting())));
            for(String key: maptj.keySet()){
                StuEnrollXwtjReVO tjrevo = new StuEnrollXwtjReVO();
                tjrevo.setFromSchoolId(StringUtils.substringBefore(key,"|"));
                tjrevo.setFromSchoolName(StringUtils.substringAfter(key, "|"));
                Map<String,Long> map1 = maptj.get(key);
                for(String key1:map1.keySet()){
                    tjrevo.setToSchoolId(StringUtils.substringBefore(key1,"|"));
                    tjrevo.setToSchoolName(StringUtils.substringAfter(key1, "|"));
                    tjrevo.setSchoolTj(map1.get(key1).intValue());
                    //----------------------
                    xxtjxxList.add(tjrevo);

                    EduSchoolVO school = eduSchoolService.getDetail(tjrevo.getFromSchoolId());
                    if("2".equals(school.getSchoolCategory())){
                        xxrs=xxrs+tjrevo.getSchoolTj();
                    }else{
                        zxrs=zxrs+tjrevo.getSchoolTj();
                    }
                }


            }
            stuEnrollTjhzVO.setXxtjrs(xxrs);
            stuEnrollTjhzVO.setZxtjrs(zxrs);
        }


        //调剂汇总

        int xwzs = 0;
        int lqrs;
        QueryWrapper<EduSchoolConfig> qw_esc = new QueryWrapper<>();
        qw_esc.select("sum(enrolment) enrolment")
                .eq("Del",0)
                .in("school_category",2,3)
                .eq("year",vo.getYear())
                .eq("area_code",vo.getAreaCode());
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qw_esc.eq("school_category",vo.getSchoolCategory());
        }
        Map<String, Object> mapesc = eduSchoolConfigService.getMap(qw_esc);
        if(!ObjectUtils.isEmpty(mapesc)){
            xwzs= Integer.parseInt(mapesc.get("enrolment").toString());
        }

        QueryWrapper<EduStudentEnroll> qw_rol = new QueryWrapper<>();
        qw_rol.select("student_enroll_id")
                .eq("Del",0)
                .in("school_category",2,3)
                .eq("year",vo.getYear())
                .eq("enroll_status","2")
                .eq("area_code",vo.getAreaCode());
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qw_rol.eq("school_category",vo.getSchoolCategory());
        }
        List<EduStudentEnroll> list_rol= eduStudentEnrollService.list(qw_rol);
        lqrs = list_rol.size();
        stuEnrollTjhzVO.setKyxw(xwzs-lqrs);
        sexwvo.setStuEnrollTjhzVO(stuEnrollTjhzVO);

        //------------------------------------------------
        if (vo.getPageNum() == null || vo.getPageSize() == null || vo.getPageSize() == 0) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(10);
        }else{
            vo.setPageNum(vo.getPageNum()+1);
        }
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List listPage = page(xxdtjxxList,vo.getPageNum(),vo.getPageSize());
        PageInfo<StuEnrollXxtjVO> pageInfo = new PageInfo(xxdtjxxList);
        xxdtjxxList = PagerUtil.parsePagerVo(listPage, pageInfo).getList();

        sexwvo.setXxdtjxxList(xxdtjxxList);

        List listPage2 = page(xxtjxxList,vo.getPageNum(),vo.getPageSize());
        PageInfo<StuEnrollXwtjReVO> pageInfo2 = new PageInfo(xxtjxxList);
        xxtjxxList = PagerUtil.parsePagerVo(listPage2, pageInfo2).getList();
        sexwvo.setXxtjxxList(xxtjxxList);

        return sexwvo;
    }
    @Override
    @OpApi(funcCode = "EduAnalysisXq0026", title = "学校待调剂信息", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public PageInfo<StuEnrollXxtjVO> getStuEnrollXxdtjxx(StuEnrollXxtjxxInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }

        if (vo.getPageNum() == null || vo.getPageSize() == null || vo.getPageSize() == 0) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(10);
        }else{
            vo.setPageNum(vo.getPageNum()+1);
        }
        //页标按传入的加1作为分页页标

        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());

        List<StuEnrollXxtjVO> yxlist= eduEnrolYbmService.getStuEnrollXxtjList(vo);

        return (PageInfo<StuEnrollXxtjVO>) new PageInfo(yxlist);
    }
    @Override
    @OpApi(funcCode = "EduAnalysisXq0027", title = "学校调剂信息", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public PageInfo<StuEnrollXwtjReVO> getStuEnrollXxtjxx(StuEnrollXxtjxxInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }

        if (vo.getPageNum() == null || vo.getPageSize() == null || vo.getPageSize() == 0) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(10);
        }else{
            vo.setPageNum(vo.getPageNum()+1);
        }
        //页标按传入的加1作为分页页标
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<StuEnrollXwtjReVO> li =  eduEnrolYbmService.getStuEnrollXwtjReList(vo);
        return (PageInfo<StuEnrollXwtjReVO>) new PageInfo(li);
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0028", title = "学生画像", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public StuXshxVO getStuXshx(StuXshxInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        StuXshxVO xshxvo = new StuXshxVO();
        QueryWrapper<EduStudentEnroll> qw_rol = new QueryWrapper<>();
        qw_rol.select("idcard","father_idcard","mother_idcard","full_name","if(sex='1','男','女') as sex","birth_ymd",
                        "household_place")
                .eq("del","0")
                .eq("idcard",vo.getIdCard())
                .in("year",vo.getYear(),vo.getYear()-1)
                .eq("area_code",vo.getAreaCode())
                .last("limit 1");
        Map<String,Object> map_rol = eduStudentEnrollService.getMap(qw_rol);
        if(!ObjectUtils.isEmpty(map_rol)){
            String fatherIdcard =  map_rol.get("father_idcard").toString();
            String motherIdcard =  map_rol.get("mother_idcard").toString();
            //户籍信息
            StuXshxHjxxVO stuXshxHjxxVO = new StuXshxHjxxVO();
            QueryWrapper<EduHousehold> qw_HH = new QueryWrapper<>();
            qw_HH.select("full_Name","idcard","birthday","if(sex='1','男','女') as sex","address","household_Place")
                    .eq("del",0)
                    .eq("idcard",  vo.getIdCard())
                    .last("limit 1");
            Map<String,Object> map_hh = eduHouseholdService.getMap(qw_HH);
            if(!ObjectUtils.isEmpty(map_hh)){
                stuXshxHjxxVO.setAddress(map_hh.get("address").toString());
                stuXshxHjxxVO.setFullName(map_hh.get("full_Name").toString());
                stuXshxHjxxVO.setIdcard(map_hh.get("idcard").toString());
                stuXshxHjxxVO.setBirthday(map_hh.get("birthday").toString());
                stuXshxHjxxVO.setSex(map_hh.get("sex").toString());
                stuXshxHjxxVO.setHouseholdPlace(map_hh.get("household_Place").toString());
                xshxvo.setStuXshxHjxxVO(stuXshxHjxxVO);
            }

            //暂住证
            StuXshxJzzxxVO stuXshxJzzxxVO = new StuXshxJzzxxVO();
            QueryWrapper<EduLivePlace> qw_zzz = new QueryWrapper<>();
            qw_zzz.select("xm","qzrq","jzdz")
                    .eq("del",0)
                    .eq("sfzh",  vo.getIdCard())
                    .eq("year", vo.getYear());
            Map<String,Object> Map_zzz = eduLivePlaceService.getMap(qw_zzz);
            if(!ObjectUtils.isEmpty(Map_zzz)){
                stuXshxJzzxxVO.setXm(map_rol.get("full_name").toString());
                stuXshxJzzxxVO.setDz(Map_zzz.get("jzdz").toString());
                stuXshxJzzxxVO.setDjrq(Map_zzz.get("qzrq").toString());
                xshxvo.setStuXshxJzzxxVO(stuXshxJzzxxVO);
            }
            //父母参保情况
            String gx = "(父)";
            StuXshxFmcbqkVO stuXshxFmcbqkVO = new StuXshxFmcbqkVO();
            QueryWrapper<EduSocialSecurity> qw_fa = new QueryWrapper<>();
            qw_fa.select("aac003","aab004","if(aae140='110','企业养老','事业养老') as aae140"  ,"aae030","if(aac008 = '1','正常参保','终止参保') as aac008")
                    .eq("del",0)
                    .in("aae140","110","120")
                    .eq("Aac147", fatherIdcard)
                    .eq("Year", vo.getYear())
                    .orderByAsc("aae030")
                    .last("limit 1");
            Map<String,Object> map_cb1 = eduSocialSecurityService.getMap(qw_fa);
            if(!ObjectUtils.isEmpty(map_cb1)){
                stuXshxFmcbqkVO.setXm(map_cb1.get("aac003").toString()+gx+",");
                stuXshxFmcbqkVO.setCbdw(map_cb1.get("aab004").toString()+gx+",");
                stuXshxFmcbqkVO.setCkzt(map_cb1.get("aac008").toString()+gx+",");
                stuXshxFmcbqkVO.setCbkssj(map_cb1.get("aae030").toString()+gx+",");
                stuXshxFmcbqkVO.setCbxz(map_cb1.get("aae140").toString()+gx+",");
            }
            gx = "(母)";
            QueryWrapper<EduSocialSecurity> qw_mu = new QueryWrapper<>();
            qw_mu.select("aac003","aab004","if(aae140='110','企业养老','事业养老') as aae140","aae030","if(aac008 = '1','正常参保','终止参保') as aac008")
                    .eq("del",0)
                    .in("aae140","110","120")
                    .eq("Aac147", motherIdcard)
                    .eq("Year", vo.getYear())
                    .orderByAsc("aae030")
                    .last("limit 1");
            Map<String,Object> map_cb2 = eduSocialSecurityService.getMap(qw_mu);
            if(!ObjectUtils.isEmpty(map_cb2)){
                stuXshxFmcbqkVO.setXm(stuXshxFmcbqkVO.getXm()+ map_cb2.get("aac003").toString()+gx);
                stuXshxFmcbqkVO.setCbdw(stuXshxFmcbqkVO.getCbdw()+ map_cb2.get("aab004").toString()+gx);
                stuXshxFmcbqkVO.setCkzt(stuXshxFmcbqkVO.getCkzt()+ map_cb2.get("aac008").toString()+gx);
                stuXshxFmcbqkVO.setCbkssj(stuXshxFmcbqkVO.getCbkssj()+ map_cb2.get("aae030").toString()+gx);
                stuXshxFmcbqkVO.setCbxz(stuXshxFmcbqkVO.getCbxz()+ map_cb2.get("aae140").toString()+gx);
            }
            xshxvo.setStuXshxFmcbqkVO(stuXshxFmcbqkVO);
            //房产
            StuXshxFcVO stuXshxFcVO = new StuXshxFcVO();
            EnrolYbmFcVO fcvo = new EnrolYbmFcVO();
            fcvo.setYear(vo.getYear());
            fcvo.setAreaCode(vo.getAreaCode());
            fcvo.setIdcard(vo.getIdCard());
            fcvo.setFatherIdcard(fatherIdcard);
            fcvo.setMotherIdcard(motherIdcard);
            List<EnrolYbmFcVO> ervoList = getFirEnrolYbmSanVO(fcvo);
            if(!CollectionUtils.isEmpty(ervoList)){
                EnrolYbmFcVO ervo = ervoList.get(0);
                copyProperties(ervo,stuXshxFcVO);
            }

            xshxvo.setStuXshxFcVO(stuXshxFcVO);
        }
        //预报名信息
        StuXshxYbmhzVO ybmhzvo = new StuXshxYbmhzVO();
        QueryWrapper<EduStudentEnrollPre> qw_pre = new QueryWrapper<>();
        qw_pre.select("student_enroll_pre_id","school_id")
                .eq("del",0)
                .eq("idcard",vo.getIdCard())
                .eq("year", vo.getYear())
                .eq("area_code",vo.getAreaCode())
                .last("limit 1");
        Map<String,Object>map_pre = eduStudentEnrollPreService.getMap(qw_pre);
        if(!ObjectUtils.isEmpty(map_pre)){
            QueryWrapper<EduStudentEnrollBefore> qw_bef = new QueryWrapper<>();
            qw_bef.select("config_name","school_id")
                    .eq("del",0)
                    .eq("student_enroll_pre_id",map_pre.get("student_enroll_pre_id").toString())
                    .eq("year", vo.getYear())
                    .eq("area_code",vo.getAreaCode());
            List<EduStudentEnrollBefore> list_bef = eduStudentEnrollBeforeService.list(qw_bef);
            ybmhzvo.setXxs(list_bef.size());
            if(!ObjectUtils.isEmpty(map_pre.get("school_id"))){
                EduSchoolVO school = eduSchoolService.getDetail(map_pre.get("school_id").toString());
                ybmhzvo.setSchoolName(school.getSchoolName());
            }
            if(!CollectionUtils.isEmpty(list_bef)){
                List<StuXshxYbmVO> stuXshxYbmList = Convert.toList(StuXshxYbmVO.class, list_bef);
                stuXshxYbmList.forEach(item->{
                    if(!ObjectUtils.isEmpty(item.getSchoolId())){
                        EduSchoolVO school = eduSchoolService.getDetail(item.getSchoolId());
                        item.setSchoolName(school.getSchoolName());
                    }
                });

                ybmhzvo.setStuXshxYbmList(stuXshxYbmList);
                xshxvo.setStuXshxYbmhzVO(ybmhzvo);
            }
        }



        //报名信息
        StuXshxBmVO stuXshxBmVO = new StuXshxBmVO();
        StuXshxJcxxVO stuXshxJcxxVO = new StuXshxJcxxVO();
        QueryWrapper<EduStudentEnroll> qw_enroll = new QueryWrapper<>();
        qw_enroll.select("full_name","if(sex='1','男','女') as sex","household_place","address","school_Id","birth_ymd",
                        "case when enroll_status='2' then '已录取' else '未录取'end as enroll_status",
                        "case when school_category='0' then '公办' else '民办'end as school_category",
                        "case when school_nature='2' then '小学' else '中学'end as  school_nature")
                .eq("del",0)
                .eq("idcard",vo.getIdCard())
                .eq("year", vo.getYear())
                .eq("area_code",vo.getAreaCode())
                .last("limit 1");
        Map<String,Object> map_enroll = eduStudentEnrollService.getMap(qw_enroll);
        if(!ObjectUtils.isEmpty(map_enroll)){
            stuXshxBmVO.setAddress(map_enroll.get("address").toString());
            stuXshxBmVO.setFullName(map_enroll.get("full_name").toString());
            stuXshxBmVO.setSex(map_enroll.get("sex").toString());
            stuXshxBmVO.setSchoolId(map_enroll.get("school_Id").toString());
            stuXshxBmVO.setHouseholdPlace(map_enroll.get("household_place").toString());
            EduSchoolVO school = eduSchoolService.getDetail(map_enroll.get("school_Id").toString());
            if(!ObjectUtils.isEmpty(school)){
                stuXshxBmVO.setSchoolName(school.getSchoolName());
                stuXshxJcxxVO.setSchoolName(school.getSchoolName());
                stuXshxJcxxVO.setSchoolId(map_enroll.get("school_Id").toString());
                stuXshxJcxxVO.setSchoolCategory(map_enroll.get("school_category").toString());
                stuXshxJcxxVO.setSchoolNature(map_enroll.get("school_nature").toString());
                stuXshxJcxxVO.setEnrollStatus(map_enroll.get("enroll_status").toString());
            }
            String csrq = map_enroll.get("birth_ymd").toString();
            if(!ObjectUtils.isEmpty(csrq)){
                LocalDate date1 = LocalDate.now();
                DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyyMMdd");
                String dqrq = date1.format(formatter1);
                int nl1 = Integer.parseInt(StringUtils.substring(dqrq,0,4))-Integer.parseInt(StringUtils.substring(csrq,0,4));
                int nl2 = Integer.parseInt(StringUtils.substring(dqrq,4,6))-Integer.parseInt(StringUtils.substring(csrq,4,6));
                if(nl2>=0){
                    stuXshxBmVO.setNl(nl1);
                }else{
                    stuXshxBmVO.setNl(nl1-1);
                }
            }
            xshxvo.setStuXshxBmVO(stuXshxBmVO);
            xshxvo.setStuXshxJcxxVO(stuXshxJcxxVO);
        }


        return xshxvo;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0029", title = "5年趋势生成", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public FiveYearTrendVO setFiveYearTrend(FiveYearTrendVO vo) {
        //EduBigscreenFiveyearGt
        //edu_address_school_history
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        QueryWrapper<EduSchool> qw_school = new QueryWrapper<>();
        qw_school.select("org_id","school_name","school_category","school_nature")
                .eq("del","0")
                .eq("area_code",vo.getAreaCode())
                .notInSql("org_id","select school_id from edu_bigscreen_fiveyear_gt");
        List<EduSchool> list_school = eduSchoolService.list(qw_school);
        for(EduSchool esvo:list_school){
            QueryWrapper<EduStudentEnroll> qw_enrol = new QueryWrapper<>();
            qw_enrol.select("count(1) as serialNum","year")
                    .eq("del","0")
                    .eq("enroll_status","2")
                    .eq("school_id",esvo.getOrgId())
                    .between("year",vo.getYear()-5,vo.getYear())
                    .eq("area_code",vo.getAreaCode())
                    .groupBy("year");
            List<EduStudentEnroll> enrollList = eduStudentEnrollService.list(qw_enrol);
            for(EduStudentEnroll esevo:enrollList){
                //--若查询年度不存在则生成，若存在则不错处理，若查询年度等于传入年度则产出重新生成
                LambdaQueryWrapper<EduBigscreenFiveyearGt> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                lambdaQueryWrapper.eq(EduBigscreenFiveyearGt::getDel,"0");
                lambdaQueryWrapper.eq(EduBigscreenFiveyearGt::getYear, esevo.getYear());
                lambdaQueryWrapper.eq(EduBigscreenFiveyearGt::getAreaCode, vo.getAreaCode());
                List<EduBigscreenFiveyearGt> list_del = eduBigscreenFiveyearGtService.list(lambdaQueryWrapper);
                if(CollectionUtils.isEmpty(list_del)){
                    EduBigscreenFiveyearGt fyget = new EduBigscreenFiveyearGt();
                    fyget.setAreaCode(vo.getAreaCode());
                    fyget.setSchoolId(esvo.getOrgId());
                    fyget.setSchoolName(esvo.getSchoolName());
                    fyget.setSchoolCategory(esvo.getSchoolCategory());
                    fyget.setSchoolNature(esvo.getSchoolNature());
                    fyget.setYear(esevo.getYear());
                    fyget.setActNum(esevo.getSerialNum());
                    QueryWrapper<EduSchoolConfig> qw_con = new QueryWrapper<>();
                    qw_con.select("sum(enrolment) as enrolment")
                            .eq("school_id",esvo.getOrgId())
                            .eq("year",esevo.getYear())
                            .eq("area_code",vo.getAreaCode())
                            .last("limit 1");
                    Map<String,Object>map_con = eduSchoolConfigService.getMap(qw_con);
                    if(!ObjectUtils.isEmpty(map_con)){
                        fyget.setPlaNum(Integer.valueOf(map_con.get("enrolment").toString()));
                    }else{
                        fyget.setPlaNum(0);
                    }
                    eduBigscreenFiveyearGtService.save(fyget);
                }else{
                    if(Objects.equals(vo.getYear(), esevo.getYear())){
                        fyMapper.delete(lambdaQueryWrapper);

                        EduBigscreenFiveyearGt fyget = new EduBigscreenFiveyearGt();
                        fyget.setAreaCode(vo.getAreaCode());
                        fyget.setSchoolId(esvo.getOrgId());
                        fyget.setSchoolName(esvo.getSchoolName());
                        fyget.setSchoolCategory(esvo.getSchoolCategory());
                        fyget.setSchoolNature(esvo.getSchoolNature());
                        fyget.setYear(esevo.getYear());
                        fyget.setActNum(esevo.getSerialNum());
                        QueryWrapper<EduSchoolConfig> qw_con = new QueryWrapper<>();
                        qw_con.select("sum(enrolment) as enrolment")
                                .eq("school_id",esvo.getOrgId())
                                .eq("year",esevo.getYear())
                                .eq("area_code",vo.getAreaCode())
                                .last("limit 1");
                        Map<String,Object>map_con = eduSchoolConfigService.getMap(qw_con);
                        if(!ObjectUtils.isEmpty(map_con)){
                            fyget.setPlaNum(Integer.valueOf(map_con.get("enrolment").toString()));
                        }else{
                            fyget.setPlaNum(0);
                        }
                        eduBigscreenFiveyearGtService.save(fyget);
                    }
                }
            }
        }
        return vo;
    }
    @Override
    @OpApi(funcCode = "EduAnalysisXq0030", title = "学区内小区", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public PageInfo<StuEnrollXxhxXqnxqVO> getStuEnrollXxhxXqnxq(StuEnrollDgxxInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        SchoolAddressQueryVO saqvo = new SchoolAddressQueryVO();
        saqvo.setSchoolId(vo.getSchoolId());
        if (vo.getPageNum() == null || vo.getPageSize() == null || vo.getPageSize() == 0) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(10);
        }else{
            vo.setPageNum(vo.getPageNum()+1);
        }
        //页标按传入的加1作为分页页标

        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());

        List<StuEnrollXxhxXqnxqVO> xqnxqList = eduAddressSchoolService.getStuEnrollXxhxXqnxq(vo);
        return new PageInfo<>(xqnxqList);
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0031", title = "报名学生明细", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public PageInfo<StuEnrollBmmxVO> getStuEnrollBmmx(StuEnrollDgxxInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        SchoolAddressQueryVO saqvo = new SchoolAddressQueryVO();
        saqvo.setSchoolId(vo.getSchoolId());
        if (vo.getPageNum() == null || vo.getPageSize() == null || vo.getPageSize() == 0) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(10);
        }else{
            vo.setPageNum(vo.getPageNum()+1);
        }
        //页标按传入的加1作为分页页标

        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());

        QueryWrapper<EduStudentEnroll> qw_bm = new QueryWrapper<>();
        qw_bm.select("enroll_status","config_name","idcard","full_name","if(sex='1','男','女') as sex","birth_ymd","address")
                .eq("del","0")
                .eq("year",vo.getYear())
                .eq("school_id",vo.getSchoolId())
                .in("school_category",2,3)
                .eq("area_code",vo.getAreaCode());
        List<EduStudentEnroll> li_bm= eduStudentEnrollService.list(qw_bm);
        PageInfo<EduStudentEnroll> pageInfo = new PageInfo<>(li_bm);
        List<StuEnrollBmmxVO> reList = Convert.toList(StuEnrollBmmxVO.class,pageInfo.getList());
        reList.forEach(item->{
            //年龄
            String csrq = item.getBirthYmd();
            LocalDate date1 = LocalDate.now();
            DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyyMMdd");
            String dqrq = date1.format(formatter1);
            int nl1 = Integer.parseInt(StringUtils.substring(dqrq,0,4))-Integer.parseInt(StringUtils.substring(csrq,0,4));
            int nl2 = Integer.parseInt(StringUtils.substring(dqrq,4,6))-Integer.parseInt(StringUtils.substring(csrq,4,6));
            if(nl2>=0){
                item.setNl(nl1);
            }else{
                item.setNl(nl1-1);
            }
        });
        return PagerUtil.parsePagerVo(reList, pageInfo);
    }
    @Override
    @OpApi(funcCode = "EduAnalysisXq0032", title = "预采集人员户籍信息生成", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public StuEnrollInVO getStuHjxx(StuEnrollInVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        LambdaQueryWrapper<EduAnalyHj> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EduAnalyHj::getAreaCode,vo.getAreaCode());
        lambdaQueryWrapper.eq(EduAnalyHj::getYear, vo.getYear());
        List<EduAnalyHj> list_del = eduAnalyHjService.list(lambdaQueryWrapper);
        if(!CollectionUtils.isEmpty(list_del)){
            eduAnalyHjMapper.delete(lambdaQueryWrapper);
        }

        QueryWrapper<EduStudentEnrollPre> qwesep = new QueryWrapper<>();
        qwesep.select("idcard","school_category","father_idcard","mother_idcard","school_id","year")
                .eq("Del",0)

                .in("school_category",2,3)
                //.notIn("school_id","E3392DF5-109B-4E83-9E94-033AF27506E6","5D805C74-6D25-4ACC-ADE5-A5F538973769")
                .eq("Area_Code",vo.getAreaCode());
        if(!ObjectUtils.isEmpty(vo.getStreet())){
            qwesep.eq("Street",vo.getStreet());
        }
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qwesep.eq("School_Category",vo.getSchoolCategory());
        }
        List<EduStudentEnrollPre> listesep = eduStudentEnrollPreService.list(qwesep);
        listesep.forEach(item -> {
            EduAnalyHj eah = new EduAnalyHj();
            eah.setSchoolId(item.getSchoolId());
            eah.setYear(item.getYear()+"");
            eah.setAreaCode(vo.getAreaCode());
            eah.setIdcard(item.getIdcard());
            eah.setSchoolCategory(item.getSchoolCategory());
            eah.setHjType(getBdhj(item.getIdcard(),item.getFatherIdcard(),item.getMotherIdcard(),vo.getYear(),vo.getAreaCode())+"");
            eah.setFatherIdcard(item.getFatherIdcard());
            eah.setMotherIdcard(item.getMotherIdcard());
            eduAnalyHjService.save(eah);
        });
        return vo;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0033", title = "学校人数统计表生成", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public StuRsVO acqSchoolRs(StuRsVO vo) {
        if(ObjectUtils.isEmpty(vo.getYear())){
            vo.setYear(eduHelper.thisYear());
        }
        if(ObjectUtils.isEmpty(vo.getAreaCode())){
            CommonVO commonVO=new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode=commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        QueryWrapper<EduSchoolConfig> qw_con = new QueryWrapper<>();
        qw_con.select("school_id","year","enrolment","config_type_name")
                .eq("Del",0)
                .in("school_category",2,3)
                .eq("Area_Code",vo.getAreaCode());
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qw_con.eq("School_Category",vo.getSchoolCategory());
        }
        List<EduSchoolConfig> listesep = eduSchoolConfigService.list(qw_con);
        for(EduSchoolConfig esCon:listesep){
            EduSchoolVO eduSchool = eduSchoolService.getDetail(esCon.getSchoolId());
            if(!ObjectUtils.isEmpty(eduSchool)){
                EduSchoolRs ess = new EduSchoolRs();
                ess.setSchoolId(eduSchool.getOrgId());
                ess.setYear(esCon.getYear());
                ess.setAreaCode(vo.getAreaCode());
                ess.setSchoolCategory(eduSchool.getSchoolCategory());
                ess.setSchoolName(eduSchool.getSchoolName());
                ess.setSchoolNature(eduSchool.getSchoolNature());
                ess.setPlaNum(esCon.getEnrolment());
                ess.setLatitude(eduSchool.getLatitude());
                ess.setLongitude(eduSchool.getLongitude());
                if(!ObjectUtils.isEmpty(esCon.getConfigTypeName()) && "寄宿".equals(esCon.getConfigTypeName())){
                    ess.setConfigType("1");
                    ess.setConfigTypeName("住校");
                }else {
                    ess.setConfigType("0");
                    ess.setConfigTypeName("非住校");
                }

                GetDictVO gdvo = new GetDictVO();
                gdvo.setDictField("SCHOOLCATEGORY");
                gdvo.setDictKey(eduSchool.getSchoolCategory());
                gdvo.setAstype("1");
                ess.setSchoolCategoryName(getDictName(gdvo).getDictValue());
                gdvo = new GetDictVO();
                gdvo.setDictField("SCHOOLNATURE");
                gdvo.setDictKey(eduSchool.getSchoolCategory());
                gdvo.setAstype("1");
                ess.setSchoolNatureName(getDictName(gdvo).getDictValue());
                int sigNum = 0;
                int admNum = 0;
                QueryWrapper<EduStudentEnroll> qw_bm = new QueryWrapper<>();
                qw_bm.select("if(enroll_status=2,'2','0') enroll_status")
                        .eq("del","0")
                        .eq("year",esCon.getYear())
                        .eq("school_id",esCon.getSchoolId())
                        .in("school_category",2,3)
                        .eq("area_code",vo.getAreaCode());
                if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
                    qw_bm.eq("School_Category",vo.getSchoolCategory());
                }
                List<EduStudentEnroll> li_bm= eduStudentEnrollService.list(qw_bm);
                if(!CollectionUtils.isEmpty(li_bm)){
                    Map<String,Long> map = li_bm.stream().filter(item->
                            StringUtil.isNotBlank(item.getEnrollStatus())
                    ).collect(Collectors.groupingBy(EduStudentEnroll::getEnrollStatus,Collectors.counting()));
                    if(!ObjectUtils.isEmpty(map)){
                        for(String key:map.keySet()){
                            int value = map.get(key).intValue();
                            if("2".equals(key)){
                                admNum=admNum+value;
                            }
                            sigNum=sigNum+value;
                        }
                        ess.setAdmNum(admNum);
                        ess.setSigNum(sigNum);
                    }else{
                        ess.setAdmNum(0);
                        ess.setSigNum(0);
                    }
                    eduSchoolRsService.save(ess);
                }
            }

        }

//        SchoolConfigQueryVO ssvo = new SchoolConfigQueryVO();
//        ssvo.setYear(2023);
//        List<SchoolConfigVO> getSchoolConfigInfo =  eduSchoolConfigService.getSchoolConfigInfo(ssvo);
//        getSchoolConfigInfo.forEach(item->{
//             EduSchoolConfig config = new EduSchoolConfig();
//            config.setAreaCode(item.getAreaCode());
//            config.setSchoolCategory(item.getSchoolCategory());
//            config.setSchoolId(item.getSchoolId());
//            config.setSchoolNature(item.getSchoolNature());
//            config.setYear(2022);
//            config.setAuthRemarks(item.getAuthRemarks());
//            config.setAuthStatus(item.getAuthStatus());
//            config.setAuthTime(item.getAuthTime());
//            config.setAuthUserId(item.getAuthUserId());
//            config.setClassNum(item.getClassNum());
//            config.setConfigType(item.getConfigType());
//            config.setConfigTypeName(item.getConfigTypeName());
//            config.setStatus(item.getStatus());
//            config.setEnrolment(item.getEnrolment());
//
//            eduSchoolConfigService.save(config);
//        });

        return vo;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0034", title = "学校人数统计", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public List<StuRsTjVo> getSchoolRs(StuRsInVO vo) {
        if (ObjectUtils.isEmpty(vo.getYear())) {
            vo.setYear(eduHelper.thisYear());
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            CommonVO commonVO = new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode = commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        if (ObjectUtils.isEmpty(vo.getAddress())) {
            throw new AppException("地址不能为空");
        }

        List<StuRsTjVo> resultList = new ArrayList<>();
        AddressReqVO add = new AddressReqVO();
        add.setAddress(vo.getAddress());
        AddressAndSchoolVO aasvo = eduAddressTreeIntegrationImpl.parseAddressAndMatchSchool(add);
        if(!ObjectUtils.isEmpty(aasvo)){
            Map<String, List<EduSchoolVO>> matchSchools = aasvo.getMatchSchools();
            for (String key:matchSchools.keySet()){
                List<StuRsTjListVO> stuRsTjList = new ArrayList<>();
                List<EduSchoolVO> scList = matchSchools.get(key);
                for(EduSchoolVO scvo:scList){
                    StuRsTjVo tjvo = new StuRsTjVo();
                    String schoolId = scvo.getOrgId();
                    tjvo.setSchoolId(schoolId);
                    tjvo.setAreaCode(scvo.getAreaCode());
                    tjvo.setSchoolName(scvo.getSchoolName());
                    tjvo.setSchoolCategory(scvo.getSchoolCategory());
                    tjvo.setSchoolNature(scvo.getSchoolNature());
                    tjvo.setLatitude(scvo.getLatitude().toString());
                    tjvo.setLongitude(scvo.getLongitude().toString());
                    tjvo.setSchoolCategoryName(scvo.getSchoolCategoryName());
                    tjvo.setSchoolNatureName(scvo.getSchoolNatureName());

                    QueryWrapper<EduSchoolRs> qw_esrs = new QueryWrapper<>();
                    qw_esrs.eq("Del",0)
                            .between("year",vo.getYear()-5,vo.getYear())
                            .eq("school_id",schoolId);
                    List<EduSchoolRs> listesrs = eduSchoolRsService.list(qw_esrs);
                    for(EduSchoolRs rs:listesrs){
                        StuRsTjListVO tjlistvo = new StuRsTjListVO();
                        tjlistvo.setYear(rs.getYear());
                        tjlistvo.setAdmNum(rs.getAdmNum());
                        tjlistvo.setSigNum(rs.getSigNum());
                        tjlistvo.setPlaNum(rs.getPlaNum());
                        stuRsTjList.add(tjlistvo);

                    }
                    tjvo.setStuRsTjList(stuRsTjList);
                    resultList.add(tjvo);
                }
            }
        }

////        AddressAndSchoolVO aasvo=JSON.parseObject("",AddressAndSchoolVO.class);
//        String url = "http://zsbm.dyedu.net/dyedu/doc/api/eduAddressTree0018";
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("address", vo.getAddress());
//        String post = HttpUtil.createPost(url).header("accessToken", "c90fdbb0125a49159e14ec578094ca3f")
//                .body(jsonObject.toJSONString()).execute().body();
//        List<StuRsTjVo> resultList = new ArrayList<>();
//        if (!ObjectUtils.isEmpty(JSONObject.parseObject(post).getJSONObject("result"))) {
//            JSONObject jso = JSONObject.parseObject(post).getJSONObject("result").getJSONObject("matchSchools");
//            if (!ObjectUtils.isEmpty(vo.getSchoolCategory())) {
//                JSONArray resultalist = JSON.parseArray(jso.get(vo.getSchoolCategory()).toString());
//
//                for (Object rlist : resultalist) {
//                    StuRsTjVo tjvo = new StuRsTjVo();
//                    List<StuRsTjListVO> stuRsTjList = new ArrayList<>();
//                    String schoolId = JSONObject.parseObject(rlist.toString()).get("orgId").toString();
//                    tjvo.setSchoolId(schoolId);
//                    tjvo.setAreaCode(JSONObject.parseObject(rlist.toString()).get("areaCode").toString());
//                    tjvo.setSchoolName(JSONObject.parseObject(rlist.toString()).get("schoolName").toString());
//                    tjvo.setSchoolCategory(JSONObject.parseObject(rlist.toString()).get("schoolCategory").toString());
//                    tjvo.setSchoolNature(JSONObject.parseObject(rlist.toString()).get("schoolNature").toString());
//                    tjvo.setLatitude(JSONObject.parseObject(rlist.toString()).get("latitude").toString());
//                    tjvo.setLongitude(JSONObject.parseObject(rlist.toString()).get("longitude").toString());
//
//                    QueryWrapper<EduSchoolRs> qw_esrs = new QueryWrapper<>();
//                    qw_esrs.eq("Del", 0)
//                            .between("year", vo.getYear() - 5, vo.getYear())
//                            .eq("school_id", schoolId);
//                    List<EduSchoolRs> listesrs = eduSchoolRsService.list(qw_esrs);
//                    for (EduSchoolRs rs : listesrs) {
//                        StuRsTjListVO tjlistvo = new StuRsTjListVO();
//                        tjlistvo.setYear(rs.getYear());
//                        tjlistvo.setAdmNum(rs.getAdmNum());
//                        tjlistvo.setSigNum(rs.getSigNum());
//                        tjlistvo.setPlaNum(rs.getPlaNum());
//                        stuRsTjList.add(tjlistvo);
//                    }
//                    tjvo.setStuRsTjList(stuRsTjList);
//                    resultList.add(tjvo);
//                }
//            } else {
//                for (String key : jso.keySet()) {
//                    String k = key;
//                    JSONArray resultalist = JSON.parseArray(jso.get(k).toString());
//
//                    for (Object rlist : resultalist) {
//                        StuRsTjVo tjvo = new StuRsTjVo();
//                        List<StuRsTjListVO> stuRsTjList = new ArrayList<>();
//                        String schoolId = JSONObject.parseObject(rlist.toString()).get("orgId").toString();
//                        tjvo.setSchoolId(schoolId);
//                        tjvo.setAreaCode(JSONObject.parseObject(rlist.toString()).get("areaCode").toString());
//                        tjvo.setSchoolName(JSONObject.parseObject(rlist.toString()).get("schoolName").toString());
//                        tjvo.setSchoolCategory(JSONObject.parseObject(rlist.toString()).get("schoolCategory").toString());
//                        tjvo.setSchoolNature(JSONObject.parseObject(rlist.toString()).get("schoolNature").toString());
//
//                        QueryWrapper<EduSchoolRs> qw_esrs = new QueryWrapper<>();
//                        qw_esrs.eq("Del", 0)
//                                .between("year", vo.getYear() - 5, vo.getYear())
//                                .eq("school_id", schoolId);
//                        List<EduSchoolRs> listesrs = eduSchoolRsService.list(qw_esrs);
//                        for (EduSchoolRs rs : listesrs) {
//                            StuRsTjListVO tjlistvo = new StuRsTjListVO();
//                            tjlistvo.setYear(rs.getYear());
//                            tjlistvo.setAdmNum(rs.getAdmNum());
//                            tjlistvo.setSigNum(rs.getSigNum());
//                            tjlistvo.setPlaNum(rs.getPlaNum());
//                            stuRsTjList.add(tjlistvo);
//                        }
//                        tjvo.setStuRsTjList(stuRsTjList);
//                        resultList.add(tjvo);
//                    }
//
//                }
//            }
//        }else{
//            throw new AppException(JSONObject.parseObject(post).getJSONObject("message").toString());
//        }

        return resultList;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0035", title = "根据经纬度取15km内学校人数统计", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public List<StuRsFromLatLngVO> getSchoolRsFromLatLng(StuRsFromLatLngInVO vo) {
        if (vo.getLatitude() == null || vo.getLongitude() == null) {
            return new ArrayList<>();
        }
        if (ObjectUtils.isEmpty(vo.getYear())) {
            vo.setYear(eduHelper.thisYear());
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            CommonVO commonVO = new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode = commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }

        QueryWrapper<EduSchoolRs> qw_es = new QueryWrapper<>();
        qw_es.select("school_id,area_code,school_name,School_Category,School_Nature," +
                        "School_Category_Name,school_Nature_Name,Latitude,Longitude")
                .eq("Del",0)
                .between("year",vo.getYear()-5,vo.getYear())
                .isNotNull("longitude")
                .isNotNull("latitude");
        if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
            qw_es.eq("School_Category",vo.getSchoolCategory());
        }
        if(!ObjectUtils.isEmpty(vo.getConfigType())){
            qw_es.eq("config_type",vo.getConfigType());
        }
        qw_es.groupBy("school_id,area_code,school_name,School_Category,School_Nature,School_Category_Name,school_Nature_Name,Latitude,Longitude");
        List<EduSchoolRs> listes = eduSchoolRsService.list(qw_es);

        List<StuRsFromLatLngVO> resultList = Convert.toList(StuRsFromLatLngVO.class,listes);
        resultList.forEach(item->{
                double d = distanceByLongNLat(
                        vo.getLongitude().doubleValue(),
                        vo.getLatitude().doubleValue(),
                        Double.parseDouble(item.getLongitude()),
                        Double.parseDouble(item.getLatitude()));
                if(d<=vo.getRaidus()){
                    List<StuRsTjListVO> stuRsTjList = new ArrayList<>();
                    QueryWrapper<EduSchoolRs> qw_esrs = new QueryWrapper<>();
                    qw_esrs.eq("Del",0)
                            .between("year",vo.getYear()-5,vo.getYear())
                            .isNotNull("longitude")
                            .isNotNull("latitude")
                            .eq("school_id",item.getSchoolId());
                    if(!ObjectUtils.isEmpty(vo.getSchoolCategory())){
                        qw_esrs.eq("School_Category",vo.getSchoolCategory());
                    }
                    if(!ObjectUtils.isEmpty(vo.getConfigType())){
                        qw_es.eq("config_type",vo.getConfigType());
                    }
                    List<EduSchoolRs> listesrs = eduSchoolRsService.list(qw_esrs);
                    for(EduSchoolRs rs:listesrs){
                        StuRsTjListVO tjlistvo = new StuRsTjListVO();
                        tjlistvo.setYear(rs.getYear());
                        tjlistvo.setAdmNum(rs.getAdmNum());
                        tjlistvo.setSigNum(rs.getSigNum());
                        tjlistvo.setPlaNum(rs.getPlaNum());
                        stuRsTjList.add(tjlistvo);
                    }
                    item.setDistance(Math.ceil(d));
                    item.setStuRsTjList(stuRsTjList);
                }
        });
        if (vo.getPageNum() == null || vo.getPageSize() == null || vo.getPageSize() == 0) {
            //如果不传入分页参数，默认最大取1000条
            vo.setPageNum(1);
            vo.setPageSize(10);
        }else{
            vo.setPageNum(vo.getPageNum()+1);
        }
        //页标按传入的加1作为分页页标
        PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        List<StuRsFromLatLngVO> resultList1  = resultList.stream().filter(item ->item.getStuRsTjList() != null).collect(Collectors.toList());
        PageInfo<StuRsFromLatLngVO> pageInfo = new PageInfo<>(resultList1);
        return resultList1;
    }

    @Override
    @OpApi(funcCode = "EduAnalysisXq0038", title = "第一个屏指标数据生成", funcType = FuncTypeEnum.other ,checkPrivilege = BoolEnum.FALSE,publicFlag =BoolEnum.TRUE)
    public void insertEduBigscreenZbtj(SchoolOverviewXqQueryVO vo) {
        if (ObjectUtils.isEmpty(vo.getYear())) {
            vo.setYear(eduHelper.thisYear());
        }
        if (ObjectUtils.isEmpty(vo.getAreaCode())) {
            CommonVO commonVO = new CommonVO();
            commonVO.setParamKey("area_code");
            String areaCode = commonIntegration.getValueByKey(commonVO);
            vo.setAreaCode(areaCode);
        }
        //1、生成区域学位排名和学校学位排名的基础指标数据
        LambdaQueryWrapper<EduBigscreenZbtj02> lqwbigscreen02del = new LambdaQueryWrapper<>();
        lqwbigscreen02del.eq(EduBigscreenZbtj02::getDel,"0");
        lqwbigscreen02del.eq(EduBigscreenZbtj02::getYear, vo.getYear());
        lqwbigscreen02del.eq(EduBigscreenZbtj02::getAreaCode, vo.getAreaCode());
        List<EduBigscreenZbtj02> list_del = eduBigscreenZbtj02Service.list(lqwbigscreen02del);
        if(!CollectionUtils.isEmpty(list_del)){
            bigscreen02Mapper.delete(lqwbigscreen02del);
            eduBigscreenZbtj02Service.insertEduBigscreenZbtj02(vo);
        }else{
            eduBigscreenZbtj02Service.insertEduBigscreenZbtj02(vo);
        }
        //1.1、遍历生成的数据，若存在 计划招生数(学位数)为0的则取上一年的
        //1.2遍历生成的数据，若存在 适龄人数（报名数）为0的则取上一年的
        LambdaQueryWrapper<EduBigscreenZbtj02> lqwbigscreen02up = new LambdaQueryWrapper<>();
        lqwbigscreen02up.eq(EduBigscreenZbtj02::getYear, vo.getYear());
        lqwbigscreen02up.eq(EduBigscreenZbtj02::getAreaCode, vo.getAreaCode());
        List<EduBigscreenZbtj02> list_up = eduBigscreenZbtj02Service.list(lqwbigscreen02up);
        list_up.forEach(item->{
            if(Objects.equals(0, item.getStudentConCount())){
                QueryWrapper<EduSchoolConfig> queryWrapper = new QueryWrapper<>();
                queryWrapper.select("count(1) cn")
                            .eq("year",vo.getYear()-1)
                            .eq("school_id",item.getSchoolId())
                            .eq("area_code",vo.getAreaCode());
                Map<String, Object> map = eduSchoolConfigService.getMap(queryWrapper);
                if(!ObjectUtils.isEmpty(map)){
                    item.setStudentConCount(Integer.parseInt(map.get("cn").toString()));
                }
            }
            if(Objects.equals(0, item.getStudentEligCount())){
                QueryWrapper<EduEnrolYbm> queryWrapper = new QueryWrapper<>();
                queryWrapper.select("count(1) cn")
                        .eq("del","0")
                        .eq("year",vo.getYear()-1)
                        .eq("school_id",item.getSchoolId())
                        .eq("area_code",vo.getAreaCode());
                Map<String, Object> map = eduEnrolYbmService.getMap(queryWrapper);
                if(!ObjectUtils.isEmpty(map)){
                    item.setStudentEligCount(Integer.parseInt(map.get("cn").toString()));
                }
            }
            //本地户籍数和外地户籍数
            QueryWrapper<EduAnalyHj> qwhj = new QueryWrapper<>();
            qwhj.select("hj_type");
            qwhj.eq("del",0);
            qwhj.eq("year",vo.getYear());
            qwhj.eq("school_id",item.getSchoolId());
            List<EduAnalyHj> listesep = eduAnalyHjService.list(qwhj);
            if(!CollectionUtils.isEmpty(listesep)){
                Map<String,Long>map1 =  listesep.stream().collect(Collectors.groupingBy(EduAnalyHj::getHjType,Collectors.counting()));
                if(!ObjectUtils.isEmpty(map1.get("1"))){
                    item.setLocalCount(map1.get("1").intValue());
                }
                if(!ObjectUtils.isEmpty(map1.get("0"))){
                    item.setOutsideCount(map1.get("0").intValue());
                }
            }
            eduBigscreenZbtj02Service.updateById(item);
        });

        //生成第一张大屏的其他指标
        LambdaQueryWrapper<EduBigscreenZbtj01> lqwbigscreen01del = new LambdaQueryWrapper<>();
        lqwbigscreen01del.eq(EduBigscreenZbtj01::getDel,"0");
        lqwbigscreen01del.eq(EduBigscreenZbtj01::getYear, vo.getYear());
        lqwbigscreen01del.eq(EduBigscreenZbtj01::getAreaCode, vo.getAreaCode());
        List<EduBigscreenZbtj01> list01_del = eduBigscreenZbtj01Service.list(lqwbigscreen01del);
        if(!CollectionUtils.isEmpty(list01_del)){
            bigscreen01Mapper.delete(lqwbigscreen01del);
        }

        EduBigscreenZbtj01 eduBigscreenZbtj01 = new EduBigscreenZbtj01();
        eduBigscreenZbtj01.setYear(vo.getYear());
        eduBigscreenZbtj01.setAreaCode(vo.getAreaCode());
        //地址数
        QueryWrapper<EduAddress> qwaddress = new QueryWrapper<>();
        qwaddress.select("ifnull(matching_status,'0') matching_status")
                .eq("Del",0);
        List<EduAddress> list = eduAddressService.list(qwaddress);
        eduBigscreenZbtj01.setAddressCount(list.size());
        if(!CollectionUtils.isEmpty(list)){
            Map<String,Long>map1 =  list.stream().collect(Collectors.groupingBy(EduAddress::getMatchingStatus,Collectors.counting()));
            if(!ObjectUtils.isEmpty(map1.get("1"))){
                eduBigscreenZbtj01.setAddressAllocated(map1.get("1").intValue());
            }
            if(!ObjectUtils.isEmpty(map1.get("0"))){
                eduBigscreenZbtj01.setAddressUnallocated(map1.get("0").intValue());
            }
        }
        //地址数同步增长
        QueryWrapper<EduBigscreenZbtj01> qw012 = new QueryWrapper<>();
        qw012.select("address_Count")
                .eq("del","0")
                .eq("year",vo.getYear()-1)
                .eq("area_code",vo.getAreaCode());
        List<EduBigscreenZbtj01> zbtj01List = eduBigscreenZbtj01Service.list(qw012);
        if(!CollectionUtils.isEmpty(zbtj01List)){
            Map<String, Object> map = eduBigscreenZbtj01Service.getMap(qw012);
            eduBigscreenZbtj01.setAddressIncreaseCount((Integer) map.get("address_Count"));
        }else{
            eduBigscreenZbtj01.setAddressIncreaseCount(0);
        }

        //地址来源
        QueryWrapper<EduHousehold> qw_ehh = new QueryWrapper<>();
        qw_ehh.select("count(distinct address_id) as cn")
                .eq("Del",0)
                .isNotNull("address_id");
        Map<String,Object>map_ehh = eduHouseholdService.getMap(qw_ehh);
        if(!ObjectUtils.isEmpty(map_ehh)){
            int cn = Integer.parseInt(map_ehh.get("cn").toString());
            eduBigscreenZbtj01.setSouHousehold(cn);
        }
        QueryWrapper<EduHouse> qw_eh = new QueryWrapper<>();
        qw_eh.select("count(distinct address_id) as cn")
                .eq("Del",0)
                .isNotNull("address_id");
        Map<String,Object>map_eh = eduHouseService.getMap(qw_eh);
        if(!ObjectUtils.isEmpty(map_eh)){
            int cn = Integer.parseInt(map_eh.get("cn").toString());
            eduBigscreenZbtj01.setSouHouse(cn);
        }
        eduBigscreenZbtj01.setSouOthers(eduBigscreenZbtj01.getAddressCount()-eduBigscreenZbtj01.getSouHouse()-eduBigscreenZbtj01.getSouHousehold());

        eduBigscreenZbtj01Service.save(eduBigscreenZbtj01);

    }


    private List<AreaXwpmVO> getAreaXwpmVO(SchoolOverviewXqQueryVO vo) {
        return eduSchoolService.getAreaXwpmVO(vo);
    }
    private List<EnrolYbmVO> getFirEnrolYbmVO(EnrolYbmVO vo) {
        return eduStudentEnrollBeforeService.getFirEnrolYbmVO(vo);
    }

    private List<StuEnrollXzjdpmVO> getStuEnrollXzjdpmVO(StuEnrollInVO vo) {
        return eduStudentEnrollService.getStuEnrollXzjdpmVO(vo);
    }

    private EnrolYbmVO getEnrolYbmCalculateVO(EnrolYbmVO vo) {
        return eduStudentEnrollBeforeService.getEnrolYbmCalculateVO(vo);
    }

    private List<EnrolYbmVO> getFirEnrolYbmCalculateVO(EnrolYbmVO vo) {
        return eduStudentEnrollBeforeService.getFirEnrolYbmCalculateVO(vo);
    }
    private List<EnrolYbmXxRyVO> getEnrolYbmXxRyVO(EnrolYbmXxRyInVO vo) {
        return eduStudentEnrollBeforeService.getEnrolYbmXxRyVO(vo);
    }

    private EnrolYbmVO getEnrolYbmVO(EnrolYbmVO vo) {
        return eduStudentEnrollBeforeService.getEnrolYbmVO(vo);
    }

    private List<EnrolYbmFcVO> getFirEnrolYbmSanVO(EnrolYbmFcVO vo) {
        return eduStudentEnrollBeforeService.getFirEnrolYbmSanVO(vo);
    }

    private StuEnrollGlblqlVO getStuEnrollGlblqlVO(String schoolId,int year,String areaCode) {
        StuEnrollGlblqlVO vo = new StuEnrollGlblqlVO();
        QueryWrapper<EduStudentEnroll> qwyx = new QueryWrapper<>();
        qwyx.select(" case when enroll_Status ='2' then '2' else '0' end as enroll_Status","config_name")
                .eq("Del",0)
                .eq("year",year)
                .eq("area_code",areaCode)
                .in("school_category",2,3)
                .in("config_name","A","B","C");
        if(!ObjectUtils.isEmpty(schoolId)){
            qwyx.eq("school_id",schoolId);
        }
        List<EduStudentEnroll> yxlist1= eduStudentEnrollService.list(qwyx);
        if(!CollectionUtils.isEmpty(yxlist1)){
            Map<String,Map<String,Long>> map = yxlist1.stream().filter(item->
                    //做非空判断
                    StringUtil.isNotBlank(item.getEnrollStatus())&&
                            StringUtil.isNotBlank(item.getConfigName())
            ).collect(Collectors.groupingBy(EduStudentEnroll::getConfigName,Collectors.groupingBy(EduStudentEnroll::getEnrollStatus,Collectors.counting())));

            int azs = 0;
            int bzs = 0;
            int czs = 0;
            int al = 0;
            int bl = 0;
            int cl = 0;
            for(String key:map.keySet()){
                Map<String,Long> map1 = map.get(key);
                for(String key1:map1.keySet()){
                    int value = map1.get(key1).intValue();
                    if("A".equals(key)){
                        azs = azs+value;
                        if("2".equals(key1)){
                            al = value;

                        }
                    }
                    if("B".equals(key)){
                        bzs = bzs+value;
                        if("2".equals(key1)){
                            bl = value;

                        }
                    }
                    if("C".equals(key)){
                        czs = czs+value;
                        if("2".equals(key1)){
                            cl = value;
                        }
                    }
                }
            }

            if(azs!=0){
                vo.setAlei(Double.valueOf(String.format("%.2f", (double) al/azs)));
            }
            if(bzs!=0){
                vo.setBlei(Double.valueOf(String.format("%.2f", (double) bl/bzs)));
            }
            if(czs!=0){
                vo.setClei(Double.valueOf(String.format("%.2f", (double) cl/czs)));
            }
        }
        return vo;
    }

    private List<SchoolXwpmVO> getSchoolXwpmVO(SchoolXwpmQueryVO vo) {
        return eduSchoolService.getSchoolXwpmVO(vo);
    }
    private List<SchoolXqVO> getSchoolXqVOList(SchoolXqQueryVO vo) {
        return eduSchoolService.getSchoolXqVOList(vo);
    }

    private List<SchoolAddressCountVO> getSchoolAddressCountVO(AddressOverviewXqQueryVO vo) {
        return eduAddressSchoolService.getSchoolAddressCountVO(vo);
    }

    private SchoolXqVO getSchoolXqVO(SchoolXqQueryVO vo) {
        return eduSchoolService.getSchoolXqVO(vo);
    }

    private int getBdhj(String inIdcode,String inFatherIdcard,String inMotherIdcard,int year,String areaCode){
        //判断是否本地户籍
        int cn = 0;
        //getFirEnrolYbmSanVO
        QueryWrapper<EduHousehold> qw_ehh = new QueryWrapper<>();
        qw_ehh.select("idcard")
                .eq("Del", 0)
                .like("address ","东阳")
                .eq("idcard", inIdcode);
        List<EduHousehold> l1 = eduHouseholdService.list(qw_ehh);
        if (l1.size() >= 1) {
            cn = 1;
        } else {
            EnrolYbmFcVO fcvo = new EnrolYbmFcVO();
            fcvo.setYear(year);
            fcvo.setAreaCode(areaCode);
            fcvo.setIdcard(inIdcode);
            fcvo.setFatherIdcard(inFatherIdcard);
            fcvo.setMotherIdcard(inMotherIdcard);
            List<EnrolYbmFcVO> l2 = getFirEnrolYbmSanVO(fcvo);
            if (l2.size() >= 1) {
                cn = 1;
            }
        }
        return  cn;
    }

    private GetDictVO getDictName(GetDictVO vo){
        if("1".equals(vo.getAstype())){
            DictQueryVO dictQueryVO = new DictQueryVO();
            dictQueryVO.setDictField(vo.getDictField());
            dictQueryVO.setDictKey(vo.getDictKey());
            vo.setDictValue(dictIntegration.getValue(dictQueryVO));
        }else {
            QueryWrapper<EduArea> qwpre = new QueryWrapper<>();
            qwpre.select("Area_Name")
                    .eq("local_code", vo.getDictField());
            Map<String, Object> map = eduAreaService.getMap(qwpre);
            if (!ObjectUtils.isEmpty(map)) {
                vo.setDictValue(map.get("Area_Name").toString());
            }
        }
        return vo;
    }

    private List<double[]> getArr(String str){
        String aa = str.replace("-","|");
        String[] bb = aa.replace("|"," ").split(" ");
        List<double[]> list = new ArrayList<>();
        for(String cc : bb){
            String[] dd = cc.split(",");
            double[] ee = Arrays.stream(dd).mapToDouble(Double::valueOf).toArray();
            list.add(ee);
        }
        return list;
    }

    /**
     *
     * @param list  要分页的集合
     * @param pageNo    第几页
     * @param pageSize  每页条数
     * @return      分页集合对象
     */
    public static List page(List list, int pageNo, int pageSize){
        List result = new ArrayList();
        if (list != null && list.size() > 0) {
            int allCount = list.size();
            int pageCount = (allCount + pageSize - 1) / pageSize;
            if (pageNo >= pageCount) {
                pageNo = pageCount;
            }
            int start = (pageNo - 1) * pageSize;
            int end = pageNo * pageSize;

            if(pageNo <= 0){
                start=0;
                end = 1*pageSize;
            }

            if (end >= allCount) {
                end = allCount;
            }
            for (int i = start; i < end; i++) {
                result.add(list.get(i));
            }
        }
        return (result.size() > 0) ? result : null;
    }

    /**
     * 根据经纬度和半径计算经纬度范围
     *
     * @param raidus 单位米
     * @return minLat, minLng, maxLat, maxLng
     */
    public static Map<Object,Object> getAround(double lat, double lon, int raidus) {
        Map<Object,Object> map = new HashMap<Object,Object>();
        Double latitude = lat;
        Double longitude = lon;

        double degree = (24901 * 1609) / 360.0;

        double dpmLat = 1 / degree;
        Double radiusLat = dpmLat * (double) raidus;
        Double minLat = latitude - radiusLat;
        Double maxLat = latitude + radiusLat;

        double mpdLng = degree * Math.cos(latitude * (Math.PI / 180));
        double dpmLng = 1 / mpdLng;
        Double radiusLng = dpmLng * (double) raidus;
        Double minLng = longitude - radiusLng;
        Double maxLng = longitude + radiusLng;

        map.put("minLat", minLat+"");
        map.put("maxLat", maxLat+"");
        map.put("minLng", minLng+"");
        map.put("maxLng", maxLng+"");

        return map;
    }

    /**
     * 是否在矩形区域内
     * @Title: isInArea
     * @Description:
     * @param lat 测试点经度
     * @param lng 测试点纬度
     * @param minLat 纬度范围限制1
     * @param maxLat 纬度范围限制2
     * @param minLng 经度限制范围1
     * @param maxLng 经度范围限制2
     * @return
     * @return boolean
     * @throws
     */
    public static boolean isInRectangleArea(double lat,double lng,double minLat,
                                            double maxLat,double minLng,double maxLng){
        if(isInRange(lat, minLat, maxLat)){//如果在纬度的范围内
            if(minLng*maxLng>0){
                return isInRange(lng, minLng, maxLng);
            }else {
                if(Math.abs(minLng)+Math.abs(maxLng)<180){
                    return isInRange(lng, minLng, maxLng);
                }else{
                    double left = Math.max(minLng, maxLng);
                    double right = Math.min(minLng, maxLng);
                    return isInRange(lng, left, 180) || isInRange(lng, right, -180);
                }
            }
        }else{
            return false;
        }
    }

    /**
     * 判断是否在经纬度范围内
     * @Title: isInRange
     * @Description:
     * @param point
     * @param left
     * @param right
     * @return
     * @return boolean
     * @throws
     */
    public static boolean isInRange(double point, double left,double right){
        return point >= Math.min(left, right) && point <= Math.max(left, right);
    }

    /**
     * 计算地球上任意两点(经纬度)距离
     *
     * @param long1 第一点经度
     * @param lat1  第一点纬度
     * @param long2 第二点经度
     * @param lat2  第二点纬度
     * @return 返回距离 单位：米
     */
    public static double distanceByLongNLat(double long1, double lat1, double long2, double lat2) {
        double a, b, R;
        R = 6378137;//地球半径
        lat1 = lat1 * Math.PI / 180.0;
        lat2 = lat2 * Math.PI / 180.0;
        a = lat1 - lat2;
        b = (long1 - long2) * Math.PI / 180.0;
        double d;
        double sa2, sb2;
        sa2 = Math.sin(a / 2.0);
        sb2 = Math.sin(b / 2.0);
        d = 2 * R * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1) * Math.cos(lat2) * sb2 * sb2));
        return d;
    }
}
